• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone please give me a headfirst version of what daemon/non-daemon threads are?Thanks  RSS feed

 
John McDowell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question says it all
 
Henry Wong
author
Sheriff
Posts: 22866
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John McDowell wrote:Question says it all


There are two types of threads -- user threads and daemon threads. When there are no more user threads running, the JVM will terminate.

Henry
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you looked at the JavaDocs for java.lang.Thread, the setDaemon() method, what didn't make sense to you?

Bill
 
John McDowell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:When you looked at the JavaDocs for java.lang.Thread, the setDaemon() method, what didn't make sense to you?

Bill


If jvm exits, how do the daemon threads get to run after the jvm exits? GIven that the jvm is responsible for the running of anything and everything in Java
 
Henry Wong
author
Sheriff
Posts: 22866
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John McDowell wrote:
William Brogden wrote:When you looked at the JavaDocs for java.lang.Thread, the setDaemon() method, what didn't make sense to you?


If jvm exits, how do the daemon threads get to run after the jvm exits? GIven that the jvm is responsible for the running of anything and everything in Java


I gave the answer in your other topic here...

http://www.coderanch.com/t/635818/threads/java/JVM-exits-threads-running-Daemon

And am not sure what you are confused with.... but I guess I can try again.


The JVM will terminate when there are no more user threads running. Or in other words, the JVM will terminate when there are only daemon threads running.

Think of it like this. Daemon threads are meant to help user threads, so if there are only daemon threads around, there is no need for the application to still be running. When there are only daemon threads running, the JVM terminates, and shuts everything down, including the daemon threads.

Henry
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:and shuts everything down, including the daemon threads.

I think it was this part that was confusing the OP. The docs don't actually say what happens to the daemon threads once the JVM has shut down.
It may seem obvious that they are going to be killed, but the docs don't actually explicitly say so.
 
Henry Wong
author
Sheriff
Posts: 22866
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
I think it was this part that was confusing the OP. The docs don't actually say what happens to the daemon threads once the JVM has shut down.
It may seem obvious that they are going to be killed, but the docs don't actually explicitly say so.


Yeah. I agree... but I mentioned this already in the other topic... so, I am thinking that there is something more.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!