• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a daemon thread?

 
Sudipto Ghosh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a daemon thread? When should I use setDaemon() and why?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of what you would want to know is in the API for java.lang.Thread and it's a shame that you don't read them.

A good example of an application of a daemon thread would be some type of background clean-up operation. If clean-up is only operating on the Java heap, then there is no need to delay JVM shut-down while a clean-up operation completes. If you put the clean-up operation in a Daemon thread, it won't delay shut-down.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter is right - learn to love the JavaDoc! He also gave a much nicer explanation than the JavaDoc which has some legalese double-negative convoluted wording about daemon. I always have to read it about 5 times to parse it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic