Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of Converting User thread -> Daemon thread

I read, daemon threads are used and controlled by JVM. JVM creates them and also looks after their termination.User threads are controlled by user. It is also said, we can convert a user thread to daemon thread by calling setDaemon() method.

But, what is the use of such conversion ? Does JVM takes the control of user thread once it has become a dameon thread ?

Let me know if I missed something.

Thanks.

like image 846
Saurabh Gokhale Avatar asked Dec 10 '22 11:12

Saurabh Gokhale


1 Answers

I believe that user and daemon threads are always under the JVM's control. (If that wasn't the case, who would be in charge?)

Here's the distinction (from http://www.xyzws.com/javafaq/what-is-difference-between-user-and-daemon-thread-in-java/196):

The difference between these two types of threads is straightforward: If the Java runtime determines that the only threads running in an application are daemon threads (i.e., there are no user threads in existence) the Java runtime promptly closes down the application, effectively stopping all daemon threads dead in their tracks. In order for an application to continue running, it must always have at least one live user thread. In all other respects the Java runtime treats daemon threads and user threads in exactly the same manner.

like image 73
duffymo Avatar answered Dec 27 '22 23:12

duffymo