I have a small Java application for testing purposes. I have moved to hikari recently. What I notice is that I keep getting this error.
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms. java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms. at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:602) at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:195) at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145) at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
Below is my settings for the hikari initially.
HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://localhost:3306/****"); config.setUsername("***"); config.setPassword("*****"); config.setMaximumPoolSize(20);
Hardly its being used my two devices and I ensure towards the end I do close it. So I don't know why it keep getting the error? What could be the issue or is there some settings which I need to change?
My hikari version is HikariCP-2.6.1.jar.
spring.datasource.hikari.connection-timeout=60000. Controls the maximum number of milliseconds that you will wait for setting up a connection from the pool. spring.datasource.hikari.idle-timeout=600000. Controls the maximum amount of time that a connection is allowed to sit idle in the pool.
maximum-pool-size= 10 #maximum pool size spring. datasource. hikari. idle-timeout=10000 #maximum idle time for connection spring.
"HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.
HikariConfig is the configuration class used to initialize a data source. It comes with four well-known, must-use parameters: username, password, jdbcUrl, and dataSourceClassName. Out of jdbcUrl and dataSourceClassName, we generally use one at a time.
Your database is not obtaining connection within (30000 milliseconds that is default connectionTimeout property) because of network latency or some of the queries which are taking too long to execute(more than 30000 milliseconds).
Please try to increase value of property connectionTimeout
.
YML configuration example:
spring: datasource: hikari: minimumIdle: 2 maximumPoolSize: 10 idleTimeout: 120000 connectionTimeout: 300000 leakDetectionThreshold: 300000
Java Config example:
HikariConfig config = new HikariConfig(); config.setMaximumPoolSize(20); config.setConnectionTimeout(300000); config.setConnectionTimeout(120000); config.setLeakDetectionThreshold(300000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With