Daemon threads in Java are like a service providers for other threads or objects running in the same process as the daemon thread.
Example of daemon thread is the garbage collection.
Daemon threads are used for background supporting tasks and are only needed while normal threads are executing. If normal threads are not running and remaining threads are daemon threads then the interpreter exits.
A daemon thread is a thread that does not prevent the JVM from exiting when the program finishes but the thread is still running.
Points to remember:
Default nature of a thread is non daemon because Thread inherits its daemon nature from the Thread which creates it i.e. parent Thread and since main thread (Thread class) is a non-daemon thread.
A thread will remain non-daemon until explicitly made daemon by calling setDaemon(true).
Thread should setDaemon before start it otherwise It will throw IllegalThreadStateException if corresponding Thread is already started and
Difference between Daemon and Non Daemon:
JVM doesn’t wait for any daemon thread to finish before existing.
Daemon Threads are treated differently than User Thread when JVM terminates, finally blocks are not called, Stacks are not unwounded and JVM just exits.