Thursday 8 March 2012

Daemon Threads

•In Java, there are two types of threads:
1) User threads
2) Daemon threads

•When a program contains user threads, JVM will not terminate the execution of the program unless all the user threads have completed their execution.
•When a program contains only daemon thread(s) without any user threads, then JVM can terminate the execution of the program eventhough the daemon thread(s) is/are running.
•A daemon thread is a thread which runs in the background continuously.
•A daemon thread provides services to the user threads.


•An user thread can be converted into a daemon thread by using the following method:
public final void setDaemon(boolean true/false)
•We can check whether a thread is a daemon thread or not by using the following method:
public final boolean isDaemon()
•If we create a child thread to a parent thread, and the parent thread is a daemon thread, then the child thread will also be a daemon thread automatically.

3 comments: