Skip to content

graceful shutdown

serhij.zolotukhin edited this page Dec 25, 2025 · 3 revisions

graceful shutdown

TODO:

BEST: https://medium.com/@AlexanderObregon/how-spring-boot-handles-shutdown-hooks-c4c71f593539

DONE: https://medium.com/@s2moon98/deep-diving-into-the-spring-boot-lifecycle-while-debugging-a-shutdown-issue-95d6b9995805 https://docs.spring.io/spring-boot/reference/web/graceful-shutdown.html https://www.baeldung.com/spring-boot-graceful-shutdown https://codescoddler.medium.com/spring-bean-life-cycle-34647f8fa1ab https://docs.spring.io/spring-framework/reference/core/beans/factory-nature.html

  • Graceful shutdown is enabled by default

  • @PreDestroy

  • DisposableBean

  • Bean-destroy method

  • Global ServletContextListener

Any Spring-managed object may implement the Lifecycle interface. Then, when the ApplicationContext itself receives start and stop signals , it cascades those calls to all Lifecycle implementations defined within that context. It does this by delegating to a LifecycleProcessor.

SmartLifecycle Lifecycle Phased

When starting, the objects with the lowest phase start first. When stopping, the reverse order is followed. When considering the phase value, it is also important to know that the default phase for any “normal” Lifecycle object that does not implement SmartLifecycle is 0

The default per-phase timeout is 30 seconds.

My side bar

Clone this wiki locally