1. After the main method returns. 2. After all the non daemon threads created by the application complete. 3. After all the daemon threads created by the application complete. 4. When a thread executes System.exit(); 5. When an uncaught exception is thrown in a non daemon thread. 6. When an uncaught exception is thrown in a daemon thread.
About options 5 & 6 being valid answers, I've looked at the posts, and there seem to be three answers to this: - JVM exits when an exception is not caught - JVM exits when an exception thrown from main is not caught, otherwise it doesn't - JVM doesn't exit when an exception is not caught, only the thread throwing the exception is terminated. I think the last option is correct. I hope someone clears this up, though.
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
When in doubt, write some code! Here's a snippet I just whipped up:
If you executed this, you'll see that the new thread that I spawned throws a RuntimeException instantly and dies. However, the main thread remains alive until it can print out the final statement. Therefore, if an exception goes uncaught, only the thread from which that exception was thrown is terminated abruptly. I hope that helps, Corey
hi... this is from Java How To Program 3rd Edition by Deitel & Deitel... "... A Program can include a mixture of daemon and non-daemon threads. When only daemon threads remain in a program, the program exits." hope that helps you...
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
posted
0
After all the (surviving) non daemon threads created by the application complete (which includes the thread executing main()), the . JVM will exit.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: When will JVM exit? (just one more time pls...)