Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HikariDataSource close

Tags:

java

hikaricp

I have implemented HikariCP which is working fine and I'm now planning to do a graceful shutdown of my application and I would like to make HikariCP close the database connection properly and not just killing the java application. I was reading on google and I could see the HikariDataSource should have a close method.... but in fact I'm not able to see it available:

private static DataSoure ds;
:
public blabla() {
    HikariConfig config = new HikariConfig();
    config.setJdbc(jdbcURL);
    :
    ds = new HikariDataSource(config)

In Eclipse, if I tried ds.close()... Eclipse does not showing "close" as a valid method for HikariDataSource:

enter image description here

Am i doing something wrong? Probabily.... Any idea on how to make HikariCP to close properly the database connection?

Thanks, Helio

like image 577
Helio Aymoto Avatar asked Oct 17 '25 01:10

Helio Aymoto


1 Answers

You declare ds as javax.sql.DataSource and assign it with HikariDataSource. This way you will not have access to HikariDataSource native method.

((HikariDataSource)ds).close();

would do the trick.

like image 146
ST. Kee Avatar answered Oct 18 '25 16:10

ST. Kee