aspose file tools*
The moose likes Threads and Synchronization and the fly likes JVM will not exit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "JVM will not exit?" Watch "JVM will not exit?" New topic
Author

JVM will not exit?

Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

The Java VM *will not exit* if non-Daemon threads are executing
The Java VM will exit if only Daemon threads are executing

I wonder what does the first statement mean where JVM will not exit. Suppose I have some non-Daemon threads currently running in my program, does that mean I can never exit the JVM? This does not make a lot sense to me. What happens if I force the JVM to exit by sending killing signal for example?


SCJP, SCJD, SCWCD, SCBCD, SCEA
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Neither statement is true. You can still exit by calling System.exit(), or by sending a kill -9 (in Unix) or equivalent from your OS. Both statements make more sense if we replace "will exit" and "will not exit" with "will exit on its own" and "will not exit on its own", respectively.
Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

Mike Simmons wrote:Neither statement is true. You can still exit by calling System.exit(), or by sending a kill -9 (in Unix) or equivalent from your OS. Both statements make more sense if we replace "will exit" and "will not exit" with "will exit on its own" and "will not exit on its own", respectively.


The Java VM *will not exit on its own* if non-Daemon threads are executing.
The Java VM will exit on its own if only Daemon threads are executing.

This makes sense to me. The original words were taken from some text book which obviously are confusing. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JVM will not exit?