This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on setDeamon().  RSS feed

 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code as follows:

Why there is no output? What does setDeamon() do?
Thanks advance!
 
Bert Bates
author
Sheriff
Posts: 8945
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well setDaemon isn't on the exam, so go to the next question, or see if you can refactor this code without setDaemon
 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daemmon threads are just service providers to other User threads.A daemon thread is stopped if there are no other user threads are running.When an application starts,a user thread is automatically executed to run the main() method & other threads are spawned from this main thread.
In your code the other thread that is created is a daemon thread & hence once the main thread finishes the execution ,program terminates.
 
Abdul Rehman
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bert Bates:
Well setDaemon isn't on the exam, so go to the next question, or see if you can refactor this code without setDaemon

I am always hungry for such posts...
 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!