Java 如何在系统退出(0)之前将一行打印到终端?同步问题

Java 如何在系统退出(0)之前将一行打印到终端?同步问题,java,synchronization,system.out,Java,Synchronization,System.out,目标是在调用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); 您尝试过吗?您使用的是JEE、Spr

目标是在调用
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);

您尝试过吗?您使用的是JEE、Spring还是其他什么,
System.out.flush()
是答案,谢谢!:)你试过了吗