SpringBoot 官方文档示例:(10)设置程序的退出码

香小蕉

关注

阅读 43

2022-07-27


一、实现原理:向JVM注册ShutdownHook,ShutdownHook用法如下:

package cn.edu.tju;

public class ShutdownHookTest {
public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
System.out.println("this is a shutdown hook to jvm");
}
}));
System.out.println("Hello,this is my world!");
}
}

二、实现
创建bean,实现ExitCodeGenerator

getExitCodeGenerator(){
return () -> 888;

}

程序退出时,返回的code就为888


精彩评论(0)

0 0 举报