What are Demon thread? How they are benificial than other threads? could you please explain? regards, Arun
John Dale
Ranch Hand
Joined: Feb 22, 2001
Posts: 399
posted
0
When all normal (that is, non-daemon) threads terminate, the JVM terminates. daemon threads normally used for processing that is only there to support other threads. Most of the daemon threads are managed from deep within the Java API libraries.
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
posted
0
Just to add a thought, you can make any worker-type thread into a daemon thread where it doesn't make sense for that thread to continue running after you "main" application threads stop. For example, you may have a background thread for doing simple animation loops. Rather than worry about cleaning up that thread when your main logic thread ends, you could just set that animation thread to be a daemon thread before you start it via a call to setDaemon(true); that way, when your main thread ends, and there are no more non-daemon threads running , the whole VM will exit. One thing to remember is that you can only make a thread into a daemon thread before you start it. After you call start() on a thread, it's too late to set this flag and you'll get an IllegalThreadStateException.
Rob
SCJP 1.4
arun mahajan
Ranch Hand
Joined: Dec 07, 2001
Posts: 304
posted
0
Thanks for your replies...What I could understand is that I have to write something like this to make a thread demon type: Thread t = new Thread(). t.setDemon(true) t.start() and the advantage for same....Am I right? Can you also give me some reference aricle for same on net...? regards, Arun
As we spell it in America a "Demon" is an evil spirit. In reference to threads we usually spell it "Daemon." So if you do any websearching be sure you spell it that way.
arun mahajan
Ranch Hand
Joined: Dec 07, 2001
Posts: 304
posted
0
Thanks to mention my spelling mistake....Sure I will take care of it more in future... But you know things will become "Demon" when they don't work