• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When does the JVM exit

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
I have this question.
When does the JVM exit.
1)After the main method returns.
2)After all the non demons threads created by the application complete.
3)After all the demon threads created by the application complete.
4)When a thread executes System.exit().
5)When an uncaught exception is thrown in a non demon thread.
6)When an uncaught exception is thrown in a demon thread.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)After the main method returns.
The JVM exits if there are no non-daemon threads running.
2)After all the non demons threads created by the application complete.
Always.
3)After all the demon threads created by the application complete.
Doesn't matter. The JVM will exit before they complete if all the non-daemon threads complete first.
4)When a thread executes System.exit().
Maybe. A SecurityException could be thrown or the method could block indefinitely under certain cirucmstances. Take a look at the API docs on System.exit and Runtime.exit.
5)When an uncaught exception is thrown in a non demon thread.
If the exception propagates past its run method and it is the only running non-daemon thread.

6)When an uncaught exception is thrown in a demon thread.
Nope.
[ February 15, 2004: Message edited by: Michael Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic