Daemon thread in Java
Daemon thread is a service provider thread that provides services to the user thread. Daemon thread which runs in background and mostly created by JVM for performing background task like Garbage collection and other house keeping tasks. If normal threads are not running and remaining threads are daemon threads then the interpreter exits.
Daemon thread has :
- Very low priority.
- Daemon threads acts as services in Windows.
- Only executes when no other thread of the same program is running.
- JVM ends the program finishing these threads, when daemon threads are the only threads running in a program.
You can use the setDaemon(boolean) method to change the Thread daemon properties before the thread starts. Also use isDaemon() method to check if a thread is a daemon thread or a user thread.