File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes daemon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "daemon" Watch "daemon" New topic


Syamsul Hussin
Ranch Hand

Joined: Feb 09, 2003
Posts: 59
hi, i was reading the API for thread. What is a daemon? how does it differ from normal threads? how can we use them and when should we use them? thanks

----------------------------------<br />SCJP 1.4
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Syamsul,
A daemon is a term we get from Unix. It is essentially a process that runs in the background unbeknownst to the user, like rlogind. A Java daemon thread is a thread that will not prevent the JVM from exiting when all the non-daemon thread are finished. For example if Threads A and B are non-daemons and Threads C, D and E are daemons and no other threads are running, when Threads A and B finish, the JVM will exit. I personally like to set all worker threads to daemons so that there is no chance that they can prevent the JVM from exiting.
Michael Morris
[ March 07, 2003: Message edited by: Michael Morris ]
[ March 07, 2003: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: daemon
It's not a secret anymore!