*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

poorna k
Greenhorn

Joined: Oct 16, 2000
Posts: 7
I read in one of the faqs that the below stmt is false:
The JVM runs till the main method exits, even if there are other user threads running.
isnt it true that the program terminates when the main thread dies even tho' other user threads may be executing?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
The "main thread" is just the Thread used to execute the main method. It can easily start other threads and then die.
A Java application runs until either:
1) all user Threads are finished
2) The System.exit() method is called.
There is nothing magic about the "main" thread.
Bill
poorna k
Greenhorn

Joined: Oct 16, 2000
Posts: 7
Thanks
poorna
Lahcen Mannou
Greenhorn

Joined: Oct 09, 2000
Posts: 7
A VM exits also if all the remaining threads are DEAMON threads.
Ex. Say you created 2 user threads in your main() method, thread1 and thread2 and thread1 is a Deamon thread and thread 2 is not.
If the main thread finished (end of main() method), the VM continues to run.
Now if thread2 stopps the VM stopps immediatly without waiting for thread1 to stop (because it is a Deamon thread).
Hope I'm right.
Lahcen.
Originally posted by William Brogden:
The "main thread" is just the Thread used to execute the main method. It can easily start other threads and then die.
A Java application runs until either:
1) all user Threads are finished
2) The System.exit() method is called.
There is nothing magic about the "main" thread.
Bill


[This message has been edited by Lahcen Mannou (edited October 16, 2000).]
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243

However if your main thread is destroyed, say by assigning it to null, then the JVM exits. How ever if you set other self created threads to null, the remaining threads keep running.Say you create a thread A and within A you create another thread B and then set A to null, the B thread will Keep running.
 
GeeCON Prague 2014
 
subject: Threads