This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
hi sonir! Some threads should keep running as long as the the program is running such threads are called deamon threads. Ex:Garbage collector. A Java program will terminate when all the Non-deamon threads are dead.A thread is said ti die,when it comes out of the run method.A thread may dies,but still the thread Object can exist.Understand the difference keeping in view the definition we had earlier.It is not possible to creat another threadfrom the Thread Object. Adeamon thread is automatically a deamon thread, in fact we program thread to be a deamon thread .If the code in the thread comes out of run()method it may die,even if it is specified to be a deamon thread. A deamon thread can be created by Calling setDeamon() method in the thread class.However this should be done before execution of the thread starts. [ January 10, 2002: Message edited by: Raji Addepalli ]
Originally posted by sonir shah: what are deomon and non deomon threads. I have come across a few questions which say abt these threads. what do they do? Sonir
Sonir, In Java, there are two types of threads, generally known as daemon threads and user threads. The difference between them relates to how they are managed and terminated. A user thread (which is the default type of thread you get when you create a new one) will run until it is completed. A daemon thread is a thread which will be terminated when all user threads have terminated. Therefore, daemon threads are usually useful as background processes that you'd like to have running as long as your application is running. When the user quits the application (and all user threads have been terminated) any daemon threads you have running will simply be killed. There is actually another node which has brought up a lot of information about daemon threads and user threads that you can find here. Corey