Spring boot gracefully shutdown小测试

463 阅读1分钟

小小的测试一下spring 提供的优雅关机,方便程序内部做一些特殊处理. 分别使用kill -9 强制终止程序和kill -15通知程序终止的方式进行测试. 测试命令

kill -15  $(jps | grep ApiApplication | awk '{print $1}')

或者

kill -9  $(jps | grep ApiApplication | cut -f1  -d" ")
使用命令优雅关机设置关闭时间接口执行时间关闭命令执行后程序继续运行时间(端口 释放时间)接口返回结果控制台输出结果
kill -9 pid30s15s0ssocket hang up没有日志输出,只有Process finished with exit code 137 (interrupted by signal 9: SIGKILL)
kill -9 pid30s40s0ssocket hang up没有日志输出,只有Process finished with exit code 137 (interrupted by signal 9: SIGKILL)
kill -15 pid30s15s15s返回正常结果首先打印日志Successfully waited for workers to finish,随后打印日志Graceful shutdown complete
kill -15 pid30s40s30ssocket hang up日志输出 Failed to shut down 1 bean with phase value 2147483647 <br/><br/>within timeout of 30000ms: [webServerGracefulShutdown]