| Author |
When does a thread end?
|
David Duran
Ranch Hand
Joined: Feb 11, 2002
Posts: 122
|
|
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
Joined: Jan 02, 2002
Posts: 60
|
|
|
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.
|
tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
|
 |
David Duran
Ranch Hand
Joined: Feb 11, 2002
Posts: 122
|
|
|
What is non-daemon and how would I know if it created my thread?
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
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.
|
Rob
SCJP 1.4
|
 |
 |
|
|
subject: When does a thread end?
|
|
|