来自 Spring @Component
, @PostConstruct
,如果主线程进入 hibernate 状态,例如 30 秒。
在这之间,运行 kill <pid>
会触发 SIGTERM
但在这种情况下 @PreDestroy
都不是,也不是EventListener
上ContextClosedEvent
被触发。
我们可以监听哪个 Spring 核心事件的日志,例如当一个 bean 正在 hibernate 时 PostConstruct
并且 SIGTERM 被发送到 spring boot 应用程序?
最佳答案
根据评论之一,问题是 @PostConstruct
中的逻辑太多
so your problem is actually that you're performing too much work in @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
关于java - @PostConstruct sleep 时不会触发 ContextClosedEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833334/