When does the main thread stop in Java?

前端 未结 7 2105
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 15:06

I read this statement:

The main thread must be the last thread to finish execution. When the main thread stops, the program terminates.

7条回答
  •  伪装坚强ぢ
    2020-11-27 16:07

    This is the from the JVM specification 3rd Draft, so it's the most current I'm aware of:

    5.7 Virtual Machine Exit

    The Java virtual machine terminates all its activity and exits when either: • All threads that are not daemon threads terminate. • Some thread invokes the exit method of class Runtime or class System, and the exit operation is permitted by the security manager.

    There is no distinction made about the main thread, so we shouldn't assume that is the only one that it applies to.

提交回复
热议问题