Can a java programmer can create daemon threads manually? How is it?
A:
Yes you can
Thread thread = new Thread(
new Runnable(){
public void run(){
while (true)
wait_for_action();
}
}
);
thread.start();
Lliane
2009-08-14 09:19:10
class Devil extends Thread { Devil() { setDaemon( true ); start(); } public void run() { // Perform evil tasks ... } } I got this one...Have u heard about this..
cdb
2009-08-14 09:26:11
i think setDaemon method can do the magic...
cdb
2009-08-14 09:27:27
+5
A:
Note that if not set explicitly, this property is "inherited" from the Thread that creates a new Thread.
Michael Borgwardt
2009-08-14 09:26:07
A:
You can mark a thread as a daemon using the setDaemon method provided. According to the java doc:
Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads. This method must be called before the thread is started.
This method first calls the checkAccess method of this thread with no arguments. This may result in throwing a SecurityException (in the current thread).
Here an example:
Thread someThread = new Thread(new Runnable()
{
@Override
public void run()
{
runSomething();
}
});
someThread.setDaemon(true);
someThread.start();
amoran
2010-01-27 21:34:26