Skip to content
Advertisement

Programmatically restart HikariPool in Spring Boot application?

I have a Spring Boot application which uses Hibernate, and HikariDataSource / HikariPool to talk to the database.

A special feature in the app triggers database restart. Currently this breaks the connections in HikariPool:

JavaScript

Old version of the app does call programmatically org.hibernate.SessionFactory.close(); which causes restart of HikariDataSource / HikariCP:

JavaScript

I would like to do the same, but how can I programmatically restart the connection pool in my app? I’ve seen things like Spring Boot – Handle to Hibernate SessionFactory to get a handle to sessionFactory, and maybe something similar to get a handle to DataSource or CP….but is it OK to close / restart those objects violently, is the Spring Boot context designer to handle such action properly?

There’s probably some HikariCP configuration parameters that I can start to experiment with to try reach the same end result, but replicating the old implementation tempts as the easiest / most figured out and most probable to reach same end result.

Advertisement

Answer

After some study, found out that you can get handle of HikariCP and trigger connection eviction by:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement