Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is daemon thread can alive till all the treads completes execution?  RSS feed

 
kumaraswamy dapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all , can any one tell me is Daemon Thread can exist till all the threads finish its task?
 
Piter Tosic
Greenhorn
Posts: 2
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it can but don't count on it.

First you must know that Thread is not like any other object which cease to exist when someone lose reference to it.
When Thread is started, thread can exist even if someone set reference to it to null like in this example

The point is you must assume that Thread exist until her run() method is done.
Daemon threads are not independent like ordinary threads.
They exist and stop existing, but to make sure your thread can exist until job is over. you can create thread within that daemon thread
and in that thread shift your job from daemon.
This kind of job is usually done when you need to use Thread as a Terminator for blockage on nested synch methods
but I do not recommend it because many things can go wrong.

To summary: Use Daemon threads ONLY for jobs you don't mind being suddenly stopped for other usages ORDINARY threads are better.

Hope this solves your dilemma.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!