[英]Spring boot graceful shutdown timeout callback
I created a simple spring boot application with graceful shutdown functionality by adding the following to the properties file:通过将以下内容添加到属性文件,我创建了一个简单的 spring 引导应用程序,它具有正常关闭功能:
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=1m
It works as expected.它按预期工作。
However, I would like to log information when the timeout expires before the running tasks were completed.但是,我想在运行任务完成之前超时到期时记录信息。
Is there a way to do this?有没有办法做到这一点?
Looking at DefaultLifecycleProcessor.LifecycleGroup
which is using spring.lifecycle.timeout-per-shutdown-phase
, if Spring fails to shutdown beans in specified time, then it'll log it:查看使用spring.lifecycle.timeout-per-shutdown-phase
的DefaultLifecycleProcessor.LifecycleGroup
,如果 Spring 未能在指定时间内关闭 beans,那么它会记录它:
if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) {
logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" +
(countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " +
this.phase + " within timeout of " + this.timeout + "ms: " + countDownBeanNames);
}
If you want customised implementation, you can look into implementing your own LifecycleProcessor
.如果您想要自定义实现,您可以考虑实现自己的LifecycleProcessor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.