What are daemon threads? Threads that work in the background to support the runtime environment are called daemon threads. Example garbage collector threads. When the only remaining threads in a process are daemon threads, the interpreter exits. This makes sense because when only daemon threads remain, there is no other thread for which a daemon thread can provide a service. You cannot create a daemon method but you can use, public final void setDaemon(boolean isDaemon) method, to turn it into one. What are daemon threads? The thread that provides continuous services for other threads is known as a daemon thread. For example an infinite loop in a run() method is a daemon thread. Garbage collector in java is a daemon thread which is always keeps track about orphan objects. When only daemon thread remains in the process the interpreter exits, because there are no threads to serve. We can explicitly set a thread as daemon thread by using the method setDaemon().
|