Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When does a thread end?  RSS feed

 
David Duran
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple question here, if I have a main() that calls a thread before it ends, does the program (including the thread) end when the main() ends or does the program end when the thread ends?

[ March 12, 2002: Message edited by: David Duran ]
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the thread created by main is nondaemon, the program conrinues. Otherwise when main ends, the program ends as well, that is, the vm exits.
 
David Duran
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is non-daemon and how would I know if it created my thread?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the JavaDocs for Thread. You make a thread into a deamon thread by calling setDaemon(true) on that thread.This must be done before you call start() on it.
The JVM quits ONLY when there are no non-deamon threads running. So if you create a bunch of daemon threads from main() and start them, then main() ends, the JVM will quit too. If the threads you spawn are not daemon threads, they will continue running after main() finishes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!