File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes What is Demon Thread? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "What is Demon Thread?" Watch "What is Demon Thread?" New topic
Author

What is Demon Thread?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 304
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
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
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
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
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1158

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
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

regards,
Arun
 
IntelliJ Java IDE
 
subject: What is Demon Thread?
 
Threads others viewed
What is Demon thread and what is Green thread
Multithreading
A demon Thread group ???
demon thread
demon thread
developer file tools