Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM will not exit?

 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike Simmons
Ranch Hand
Posts: 3037
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 193
Fedora Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic