![ca0a1decabdfc697297ec650df24f047.png](https://i-blog.csdnimg.cn/blog_migrate/6dc62a11b76f6ebc2696c8a682d33215.jpeg)
以下System.exti(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) *
* * @param status exit status. * @throws SecurityException * if a security manager exists and its checkExit
* method doesn't allow exit with the specified status. * @see java.lang.Runtime#exit(int) */public static void exit(int status) { Runtime.getRuntime().exit(status);}
1、System.exit(status)不管status为何值都会退出程序,终止当前正在运行的 Java 虚拟机,将JVM其中所有的内容都停掉。参数status用作状态码,非零的状态码表示异常终止。
2、System.exit(-1)、System.exit(1)是非正常退出,就是说无论程序正在执行与否,都退出。
3、System.exit(0)是正常退出,程序正常执行结束退出。