Thursday, January 14, 2021

What is a daemon thread and what are its use cases?

A daemon thread is a background service thread which runs as a low priority thread
and performs background operations like garbage collection.

So that we understand a little more about this let us compare daemons with users in the context of talking about threads:

Firstly, daemon threads are low priority threads which always run in background;  and user threads are high priority threads which always run in foreground. 

Secondly, user threads (also referred to as non-daemon) are designed to do specific or complex tasks whereas daemon threads are used to perform supporting tasks.

As long as we can keep in mind that the JVM exits if only daemon threads are remaining it makes sense in terms of their hierarchy.




No comments:

Post a Comment