How not to close Hikari pool right after Spring application gets close signal?


This Content is from Stack Overflow. Question asked by Ilia

I have Spring boot application, that goes to database using HikariCP.
The thing is, when application gets stop (SIGTERM or other) signal, it must go to database and change some data, after that it closes (“gracefull shutdown”). This logic is written in myShutdownHook (Runtime.getRuntime().addShutdownHook(myShutdownHook)). So the app needs to use connection pool for that. But problem is, that Hikari pool closes right after getting stop signal:

2022-09-18 18:26:44,796 INFO  [SpringApplicationShutdownHook] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Shutdown initiated...
2022-09-18 18:26:44,798 INFO  [SpringApplicationShutdownHook] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Shutdown completed.

And context is closing before my logic is completed. How can I make HikariCP not to close before my logic in myShutdownHook is done?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?