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

来源:互联网 发布:源码说明文档模板下载 编辑:程序博客网 时间:2024/06/03 12:59

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 classRuntime. 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 itscheckExit method doesn't allow exit with the specified status.
    See Also:
    Runtime.exit(int)

2、程序正常执行结束

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

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

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

0 0
原创粉丝点击