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

what does daemon thread means?

 
Jenny raj
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone plz explain
thank u.
 
Robert Watkins
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jenny raj:
can anyone plz explain
thank u.


Normally, when you start a new Thread, the JVM will not terminate while that thread is running. This means you need to monitor it and terminate it yourself when you want to shut the application down.

A daemon thread, by contrast, will not stop the JVM from terminating. They are good for tasks such as regular monitoring of events, or periodic polling of external systems (amongst other uses). Because they don't stop the JVM from terminating, you can treat them as "fire-and-forget" - launch them once at startup and don't worry anymore.

The event-polling thread in a Swing or AWT application is an example of a daemon thread.

(The terminolgy comes from Unix - a daemon process is one that is detached from your normal terminal session)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent overview. Robert put it so much better than the JavaDoc which says something backwards about the JVM can terminate when all threads that are not daemon threads have ended. You have to work out the missing wods that daemon threads will not prevent the JVM from terminating.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic