What is Daemon thread in java?

1 Like

A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection.

You can use the setDaemon() method to change the Thread daemon properties.

Theards which are running on the background are called deamon threads. daemon thread is a thread which doesn’t give any chance to run other threads once it enters into the run state it doesn’t give any chance to run other threads. Normally it will run forever, but when all other non-daemon threads are dead, daemon thread will be killed by JVM .