how to check HikariCP connection pooling is working or not in Java?

Tejal picture Tejal · Jul 2, 2018 · Viewed 11.6k times · Source

I have written following properties in my configuration files I am using Log4j in my application When I am running a project.

I am getting following message.does that mean connection pooling is configured in my project? if not then how it will be?

INFO: internal.ConnectionProviderInitiator - HHH000130: Instantiating explicit connection provider: com.zaxxer.hikari.hibernate.HikariConnectionProvider

I have referred following link also

link here

Datasource settings

hibernate.datasource.driver-class-name=com.mysql.jdbc.Driver
hibernate.datasource.url=jdbc:mysql://localhost:3306/mydb
hibernate.datasource.username=root
hibernate.datasource.password=root

HikariCP Settings

hibernate.hikari.dataSource.url=jdbc:mysql://localhost:3306/mydb
hibernate.hikari.idleTimeout=10
hibernate.hikari.maximumPoolSize=30
hibernate.hikari.minimumIdle=15
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource

Answer

Luis Muñoz picture Luis Muñoz · Jul 3, 2018

First, configuration is no consistent since maximum < minimumIdle. Those should be set at most to the same value.

hibernate.hikari.maximumPoolSize=10
hibernate.hikari.minimumIdle=10

If the pools is working you should see 10 ESTABLISHED connections to port 3306.

netstat -ant | grep 3306
tcp        0      0 127.0.0.1:41722     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41730     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41728     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41726     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41716     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41732     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41720     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41736     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41718     127.0.0.1:3306      ESTABLISHED 
tcp        0      0 127.0.0.1:41724     127.0.0.1:3306      ESTABLISHED