Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is daemon thread

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is daemon thread?
is it same as normal java thread?
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A daemon thread is a normal thread that does not force the JVM to remain running. Put another way, the JVM will shut down when all non-daemon threads are finished running, regardless of whether there are daemon threads still running or not.

 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And just to be clear - when the JVM shuts down and daemon threads are still running, those daemon threads will be killed.
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread we create are called user thread and when the main thread finishes its execution JVM will wait untill all the user thread completes.

But if it is the daemon thread then once your code lets say main thread is complete then JVM will not care about daemon thread and exit your program.

You can make user thread as daemon thread by calling setDaemon method.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see here
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic