System.exit退出程序

方法源码:

/**
     * Terminates the currently running Java Virtual Machine. The
     * argument serves as a status code; by convention, a nonzero status
     * code indicates abnormal termination.
     * <p>
     * This method calls the <code>exit</code> method in class
     * <code>Runtime</code>. This method never returns normally.
     * <p>
     * The call <code>System.exit(n)</code> is effectively equivalent to
     * the call:
     * <blockquote><pre>
     * Runtime.getRuntime().exit(n)
     * </pre></blockquote>
     *
     * @param      status   exit status.
     * @throws  SecurityException
     *        if a security manager exists and its <code>checkExit</code>
     *        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);
    }

这个方法将当前运行的Java虚拟结束,非0状态表示非正常退出

说明:

  1. System.exit(0)是正常退出程序,会将整个虚拟机里的内容都停掉清空
  2. System.exit(1)或者说非0表示非正常退出程序
posted @ 2019-09-02 14:16  花拾夕  阅读(3315)  评论(0编辑  收藏  举报