Daemon Thread :
Daemon threads are service provider threads. Daemon threads are used for doing some work for non-daemon threads. If program exits daemon threads also exits as they act like in supportive role for user threads.
User Threads or Non Daemon thread :
Threads created by programmer are called as User Thread. These are meant for running the program code. JVM keep running until all user thread terminates.
Daemon thread run to support user threads , if JVM finds there are no user threads to serve then JVM stops the Daemon threads. So we should not be using daemon code for programming.
Lets see the example for it, lets consider the Garbage Collector thread which acts as a daemon thread. Its work is to reclaim unused memory. When all user threads terminates, there is no need of garbage collection. so JVM stops it.
Home / Core Java / java threads / Threads / What is the difference between user threads and daemon thread?
- Blogger Comment
- Facebook Comment