SoFunction
Updated on 2025-03-02

Springboot configures Hikari connection pooling method

Springboot configures Hikari connection pool

Main configuration

as follows:

Configuration Items describe Constructor default value The value after validate is configured by default validate reset
autoCommit Automatically submit connections returned from the pool TRUE TRUE -
connectionTimeout Maximum number of milliseconds to wait for a connection from the pool (30)=30000 30000 If it is less than 250 milliseconds, it is reset back to 30 seconds
idleTimeout The maximum time the connection allows to be idle in the pool (10)=600000 600000 If idleTimeout+1 second>maxLifetime
maxLifetime The longest life cycle of connection in the pool (30)=1800000 1800000 If it is not equal to 0 and less than 30 seconds, it will be reset back to 30 minutes
connectionTestQuery If your driver supports JDBC4, we strongly recommend that you do not set this property null null -
minimumIdle Minimum number of idle connections maintained in the pool -1 10 minIdle<0 or minIdle>maxPoolSize, then it is reset to maxPoolSize
maximumPoolSize Maximum number of connections in the pool, including idle and in-use connections -1 10 If maxPoolSize is less than 1, it will be reset. When minIdle<=0 is reset to DEFAULT_POOL_SIZE, it is 10; if minIdle>0 is reset to the value of minIdle
metricRegistry This property allows you to specify an instance of Codahale/Dropwizard MetricRegistry for pool use to record various metrics null null -
healthCheckRegistry This property allows you to specify instances of Codahale/Dropwizard HealthCheckRegistry used by the pool to report current health information. null null -
poolName User-defined name of the connection pool, which mainly appears in the logging and JMX management console to identify pool and pool configurations null HikariPool-1 -
initializationFailTimeout If the pool cannot successfully initialize the connection, this property controls whether the pool will fail fast 1 1 -
isolateInternalQueries Whether to isolate internal pool queries in its own transactions, such as connection activity tests FALSE FALSE -
allowPoolSuspension Control whether the pool can be paused and restored via JMX FALSE FALSE -
readOnly Is the connection obtained from the pool in read-only mode by default FALSE FALSE -
registerMbeans Whether to register JMX management beans (MBeans) FALSE FALSE -
catalog Set default catalog for databases that support the concept of catalog driver default null -
connectionInitSql This property sets up a SQL statement that is executed before adding each new connection to the pool after it is created. null null -
driverClassName HikariCP will try to parse the driver through a DriverManager based only on jdbcUrl, but for some older drivers you must also specify driverClassName null null -
transactionIsolation Controls the default transaction isolation level of connections returned from the pool null null -
validationTimeout The maximum amount of time the connection will be tested (5)=5000 5000 If it is less than 250 milliseconds, it will be reset back to 5 seconds
leakDetectionThreshold Record the amount of time the connection may leave the pool before the message is recorded, indicating possible connection leakage 0 0 If it is greater than 0 and is not a unit test, further judgement: (leakDetectionThreshold<(2)or(leakDetectionThreshold>maxLifetime&&maxLifetime>0), it will be reset to 0. That is, if it is to take effect, it must be >0, and it cannot be less than 2 seconds, and when maxLifetime>0, it cannot be greater than maxLifetime.
dataSource This property allows you to directly set the instance of the data source to be wrapped by a pool instead of letting HikariCP construct it through reflection null null -
schema This property sets the default mode for databases that support schema concept driver default null -
threadFactory This property allows you to set instances of all threads that will be used to create the pool. null null -
scheduledExecutor This property allows you to set instances that will be used for various internal scheduled tasks null null -

Database configuration

=
 = 
 = jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf-8&useSSL=false
 = root
 = root

Hikari connection pool configuration

For detailed configuration, please visit:

/brettwooldridge/HikariCP

Minimum number of idle connections

-idle=5

The maximum time to survive in idle connections, default 600000 (10 minutes)

-timeout=180000

The maximum number of connections to the connection pool is 10 by default

-pool-size=10

This property controls the default automatic commit behavior of connections returned from the pool, with the default value: true

-commit=true

Connecting the mother and son of the pool

-name=MyHikariCP

This property controls the longest life cycle of a connection in the pool. The value 0 represents an infinite life cycle. The default is 1800000, which is 30 minutes.

-lifetime=1800000

Database connection timeout, default 30 seconds, i.e. 30,000

-timeout=30000
-test-query=SELECT 1

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.