1.

What's the difference between User thread and Daemon thread?

Answer»

User and Daemon are basically two types of thread used in JAVA by using a ‘Thread Class’.  

User Thread (Non-Daemon Thread): In Java, user THREADS have a specific LIFE cycle and its life is independent of any other thread. JVM (Java Virtual Machine) waits for any of the user threads to complete its tasks before TERMINATING it. When user threads are finished, JVM terminates the whole program along with associated daemon threads. 

Daemon Thread: In Java, daemon threads are basically REFERRED to as a service provider that provides services and support to user threads. There are basically two methods available in thread class for daemon thread: setDaemon() and isDaemon(). 

User Thread vs Daemon Thread

User ThreadDaemon Thread 
JVM waits for user threads to finish their tasks before termination. JVM does not wait for daemon threads to finish their tasks before termination.
These threads are normally created by the user for executing tasks concurrently. These threads are normally created by JVM.
They are used for critical tasks or core work of an application. They are not used for any critical tasks but to do some supporting tasks.
These threads are referred to as high-priority tasks, therefore are required for running in the foreground. These threads are referred to as low priority threads, therefore are especially required for supporting background tasks like garbage collection, releasing memory of unused objects, etc. 


Discussion

No Comment Found