问题
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
回答1:
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
回答2:
See HikariCP note about MySQL:
The MySQL DataSource is known to be broken with respect to network timeout support. Use jdbcUrl configuration instead.
You need to remove the below line and Hikari will find the driver
hibernate.datasource.driver-class-name=com.mysql.jdbc.Driver
jdbcUrl This property directs HikariCP to use "DriverManager-based" configuration. We feel that DataSource-based configuration (above) is superior
Also try adding the following as suggested when using Hibernate4:
hibernate.hikari.dataSource.url=jdbc:mysql://localhost/database hibernate.hikari.dataSource.user=bart hibernate.hikari.dataSource.password=51mp50n
回答3:
Have you tried using the app to insert/update something in the database? If it fails then it's not working.
Another way to test it is change the datasource you provided here:
hibernate.hikari.dataSource.url
to a non-existing database.Finally, change the
<Configuration status="WARN">
to<Configuration status="DEBUG">
来源:https://stackoverflow.com/questions/51136693/how-to-check-hikaricp-connection-pooling-is-working-or-not-in-java