简体   繁体   中英

sleeping while @PostConstruct does not trigger ContextClosedEvent

From a Spring @Component , @PostConstruct , if the main thread goes to sleep for, say 30 seconds.

In between, a SIGTERM is triggered by running kill <pid>

But in this case neither @PreDestroy , nor EventListener on ContextClosedEvent gets triggered.

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?

As per one of comments, problem is too much logic in @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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM