• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on setDeamon().

 
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: 8900
5
  • 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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic