Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Nandini Gangopadhyay
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a question, hopefully someone will help me......what happens to any thread which has been started in the main method when the main method exits? Does the thread terminate by itself? I think it should terminate.....Please help!
Nandini
 
nitin sharma
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
if the thread is a user thread then it keep's on running even if the main thread die.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3711
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no affect of the thread running the main() method on the threads created by main() method. Other threads keep on running as per how they are programmed even if the main thread dies.
The whole program ends only when all the non-daemon threads end.
Simple analogy, children don't die when the parents die. Do you think they should?
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Try out the world's only WebCompiler!
www.jdiscuss.com
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3711
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even daemon threads created by main won't die, if there are other non-daemon threads running.
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Try out the world's only WebCompiler!
www.jdiscuss.com
 
Nandini Gangopadhyay
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, I got it!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic