aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When does the JVM exit 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 "When does the JVM exit" Watch "When does the JVM exit" New topic
Author

When does the JVM exit

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
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.


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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 ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When does the JVM exit
 
Similar Threads
Which is right?
JVM
JVM
When does the JVM Exit?
JVM