目的是在调用System.exit(0);之前将一些消息打印到终端,例如:System.out.println("Stopping the server..."); System.exit(0); 但是应用程序在消息打印前退出。如何同步呢?使用Java JDK8 SE。 最佳答案 退出应用程序之前,您必须流。System.out.println("Stopping the server..."); System.out.flush(); System.exit(0);