-
Notifications
You must be signed in to change notification settings - Fork 0
What is an Daemon thread in Java?
Niklas edited this page Jun 10, 2021
·
1 revision
- Daemon threads can shut down any time in between their flow, Non-Daemon i.e. user thread executes completely.
- Daemon threads are threads that run intermittently in the background as long as other non-daemon threads are running.
- When all of the non-daemon threads complete, daemon threads terminates automatically.
- Daemon threads are service providers for user threads running in the same process.
- The JVM does not care about daemon threads to complete when in Running state, not even finally block also let execute. JVM do give preference to non-daemon threads that is created by us.
- Daemon threads acts as services in Windows.
- The JVM stops the daemon threads when all user threads (in contrast to the daemon threads) are terminated. Hence daemon threads can be used to implement, for example, a monitoring functionality as the thread is stopped by the JVM as soon as all user threads have stopped.
- declaration by stackoverflow