简体   繁体   中英

Spring Boot Shutdown Lifecycle

Here is the log sequence that I see when I close my Spring Boot Application. Can someone please let me know if this is the correct occurrence of the events that should happen?

2022-09-15 15:30:20.458  INFO 81214 --- [      Thread-16] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2022-09-15 15:30:22.518  INFO 81214 --- [      Thread-16] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-09-15 15:30:22.520  INFO 81214 --- [      Thread-16] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-09-15 15:30:22.529  INFO 81214 --- [      Thread-16] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

According to my understanding, I think ExecutorService is the main ThreadPoolExecutor and should be the last one to shutdown. Are the connections established between the application and database not closing safely?

That makes sense as you first shutdown the app pool meaning that no new tasks can be scheduled passed that point. Most probably shutdown routine is waiting for all already scheduked and executing tasks are complete.

Since any of those could use database connection, db closing is postponed.

After fhat is done, it is safe to shutdown db connectiin pool as.by design nothing is going to use it anymore.

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