JVM(二) java虚拟机与程序的生命周期

Java虚拟机将结束生命周期的情况:

1、执行了System.exit()方法

可以看看其官方文档是怎么说的:

  • exit

    public static void exit(int status)
    Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

    This method calls the exit method in class Runtime. This method never returns normally.

    The call System.exit(n) is effectively equivalent to the call:

     Runtime.getRuntime().exit(n)
     
    Parameters:
    status - exit status.
    Throws:
    SecurityException - if a security manager exists and its checkExit method doesn't allow exit with the specified status.
    See Also:
    Runtime.exit(int)

2、程序正常执行结束

3、程序在执行过程中遇到了异常或错误而异常终止

比如你程序没有在最上面一层进行try,catch。那么错误就会上抛到java虚拟机中导致结束。

4、由于操作系统出现错误而导致Java虚拟机进程终止

你可能感兴趣的:(★Java天堂,JVM,jvm,生命周期)