[英]sleeping while @PostConstruct does not trigger ContextClosedEvent
From a Spring @Component
, @PostConstruct
, if the main thread goes to sleep for, say 30 seconds.从 Spring @Component
, @PostConstruct
,如果主线程进入睡眠状态,例如 30 秒。
In between, a SIGTERM is triggered by running kill <pid>
在这两者之间,通过运行kill <pid>
触发 SIGTERM
But in this case neither @PreDestroy
, nor EventListener
on ContextClosedEvent
gets triggered.但在这种情况下,@ EventListener
和ContextClosedEvent
上的@PreDestroy
都不会被触发。
Which core Spring event can we listen to log for example when a bean is sleeping from PostConstruct
and a SIGTERM is sent to spring boot app?我们可以监听哪个核心 Spring 事件,例如当 bean 从PostConstruct
休眠并且 SIGTERM 发送到 spring 启动应用程序时?
As per one of comments, problem is too much logic in @PostConstruct
根据评论之一,问题是@PostConstruct
中的逻辑太多
so your problem is actually that you're performing too much work in @PostConstruct所以您的问题实际上是您在@PostConstruct 中执行了太多工作
Said another way, since Spring is still in the process of initializing itself, it probably hasn't even gotten to the step of the initialization process where if registers the shutdown hook, so it is never even notified about the SIGTERM换句话说,由于 Spring 仍在初始化过程中,它可能甚至还没有到 if 注册关闭钩子的初始化过程的步骤,因此它甚至从未通知有关 SIGTERM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.