简体   繁体   English

在 @PostConstruct 不触发 ContextClosedEvent 时睡觉

[英]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.但在这种情况下,@ EventListenerContextClosedEvent上的@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.

相关问题 当前正在运行的线程在睡眠时是否持有锁? - Does currently running thread hold the lock while sleeping? Groovy 是否尊重@PostConstruct? - Does Groovy respect @PostConstruct? 睡眠时线程中断 - Thread Interrupt while sleeping 将应用程序部署在cloudfoundry上时,spring-boot Web应用程序的ContextClosedEvent无法完成 - spring-boot web app's ContextClosedEvent does not complete when app is deployed on cloudfoundry 睡完后什么线程? 在思考 leetcode 问题时:按顺序打印 - What thread does after finishing sleeping? while thinking leetcode question: Print in Order 为什么此代码在休眠时会导致NPE,从而避免Twitter4J中的速率限制? - Why does this code result in a NPE while sleeping to avoid rate limit in Twitter4J? 似乎在具有相同锁的一个线程正在休眠时,另一个线程能够获得该锁? - How does it seem to appear that another thread is able to acquire the lock while one thread having the same lock is sleeping? 这些睡眠线程如何工作? - How does these sleeping threads work? 春天的contextstoppedevent vs contextclosedevent? - contextstoppedevent vs contextclosedevent in spring? 处理ContextClosedEvent的ApplicationListener的NullPointer警告 - NullPointer Warning for ApplicationListener handling ContextClosedEvent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM