当前位置:网站首页>6、 Configuration resolution of hikariconfig
6、 Configuration resolution of hikariconfig
2022-06-25 19:11:00 【User 1422411】
Welcome to my blog , Synchronize updates : Fengshan bieyuan
Source code version 2.4.5-SNAPSHOT
Use HikariConfig initialization HikariCP
stay 《HikariCP Initialization analysis of source code analysis 1 》 in , We analyzed HikariCP There are two ways to initialize , It mentions the use of HikariConfig The way :
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
config.setUsername("root");
config.setPassword("123");
// Set database unique properties
config.addDataSourceProperty("cachePrepStmts", "true");
// Use HikariConfig structure HikariDataSource
HikariDataSource dataSource = new HikariDataSource(config);
// Get connection from connection pool
Connection connection = dataSource.getConnection(); This method is officially recommended , The performance will be improved .HikariConfig In fact, that is HikariCP Configuration class , As we mentioned earlier HikariDataSource Inherited HikariConfig, So we can also use HikariDataSource Direct initialization HikariCP, But the performance of this method is better than that of HikariConfig Slightly worse .
Important configuration
Let's analyze today HikariCP Configuration in , Almost all configurations are HikariConfig in , yes HikariConfig Member variables of . Let's see :
/* Can be passed during operation JMX Modified properties */
// The maximum waiting time to get a connection from the connection pool , Unit millisecond , The default value is 30 second , At least 250ms
private volatile long connectionTimeout;
// Timeout to check if the connection is valid , Unit millisecond , Default 5000ms, Minimum 250ms, Not greater than connectionTimeout
//
private volatile long validationTimeout;
// The maximum idle time a connection can spend in the pool , Unit millisecond , At least 10s, Default 10 minute , 0 Means never time out , The configuration cannot be greater than maxLifetime
private volatile long idleTimeout;
// Maximum time for connection leak detection , Default 0, The minimum 2000 millisecond ; in other words , The total time from taking out the connection pool to returning the connection pool , Not beyond this time , If it exceeds the limit, it will be judged as leakage
private volatile long leakDetectionThreshold;
// Maximum connection lifetime , Unit millisecond , Minimum allowable value 30000 ms, Default 30 minute , It is recommended that the settings are better than those of the database wait_timeout A few minutes
private volatile long maxLifetime;
// The maximum number of connections that can be reserved in the connection pool , such as : 100, The number of connections in the connection pool cannot exceed 100 individual
private volatile int maxPoolSize;
// Minimum number of free connections , Default 10 individual , in other words , A maximum of... Can be reserved in the connection pool 10 Free connections , Many will be shut down
private volatile int minIdle;
/* Properties that cannot be modified at run time */
// This property sets a SQL sentence , When getting a connection from the connection pool , First implement the change sql, Verify that the connection is available , Example : select 1
// If it is used JDBC 4 It is not recommended to configure this option , because JDBC 4 Use ping command , More efficient
private String connectionTestQuery;
// Database driven dataSource Class name , And jdbcUrl, You have to choose between , If both are configured , Use this attribute first , Example : org.postgresql.ds.PGSimpleDataSource
private String dataSourceClassName;
private String dataSourceJndiName;
// Database driver class , And dataSourceClassName No coexistence , If this property is configured , that jdbcUrl Can't be empty , Example : com.mysql.jdbc.Driver
private String driverClassName;
// And dataSourceClassName, You have to choose between , If both are configured , Ignore this property , Example : jdbc:mysql://localhost:3306/simpsons
private String jdbcUrl;
// Mandatory , Database connection password
private String password;
// Connection pool name , Automatically generated by default , Hikari It is generally used for logging and JMX in , If there are more than one Hikari Connection pool , It is recommended to configure a meaningful name
private String poolName;
private String transactionIsolationName;
// Mandatory , Database connection user name
private String username;
// Auto commit transaction , The default value is true
private boolean isAutoCommit;
// Controls whether connections obtained from the pool are read-only , The database needs to support read-only mode
private boolean isReadOnly;
// The default value is true, Whether to fail quickly , That is, create a connection during startup to verify whether there are errors in key parameters , If the connection cannot be established , Throw an error immediately , It is convenient for users to find problems in time
private boolean isInitializationFailFast;
//
private boolean isIsolateInternalQueries;
// Automatic registration JMX dependent bean, Used to modify connection pool settings at runtime
private boolean isRegisterMbeans;
// Whether to allow JMX Suspend connection pool
private boolean isAllowPoolSuspension;
// Users directly specify dataSource example , Don't use Hikari Created instance
private DataSource dataSource;Not all of the above attributes , Some of the less important attributes we ignore .
HikariConfig The configuration of can be divided into two parts : Can be modified at run time , Not modifiable during runtime .
The operation period can be modified
Property name | meaning | remarks |
|---|---|---|
connectionTimeout | The maximum waiting time to get a connection from the connection pool | The default value is 30 second , At least 250ms |
validationTimeout | Timeout to check if the connection is valid | Default 5000ms, Minimum 250ms, Not greater than connectionTimeout |
idleTimeout | The maximum idle time a connection can spend in the pool | At least 10s, Default 10 minute , 0 Means never time out , The configuration cannot be greater than maxLifetime |
leakDetectionThreshold | Maximum time for connection leak detection | Default 0 Indicates that... Is not enabled , The minimum 2000 millisecond |
maxLifetime | Maximum connection lifetime | Minimum allowable value 30000 ms, Default 30 minute , It is recommended that the settings are better than those of the database wait_timeout A few minutes |
maxPoolSize | The maximum number of connections that can be reserved in the connection pool | |
minIdle | Minimum number of free connections | Default 10 individual |
The so-called runtime modifiable properties , It can be used JMX Directly modifying , We will have a 《HikariCP Source code analysis access connection process 2 》 The usage recommended by the author is mentioned in , You can have a look .
The operation period cannot be modified
Property name | meaning | remarks |
|---|---|---|
connectionTestQuery | Verify that the connection is available sql | Example : select 1, If it is used JDBC 4 It is not recommended to configure this option , because JDBC 4 Use ping command , More efficient |
dataSourceClassName | Database driven dataSource Class name | And jdbcUrl, You have to choose between , If both are configured , Use this attribute first , Example : org.postgresql.ds.PGSimpleDataSource |
driverClassName | Database driver class | And dataSourceClassName No coexistence , If this property is configured , that jdbcUrl Can't be empty , Example : com.mysql.jdbc.Driver |
jdbcUrl | url | And dataSourceClassName, You have to choose between , If both are configured , Ignore this property , Example : jdbc:mysql://localhost:3306/simpsons |
password | Database connection password | |
username | Database connection user name | |
isRegisterMbeans | Automatic registration JMX dependent bean | Used to modify connection pool settings at runtime |
isAllowPoolSuspension | Whether to allow JMX Suspend connection pool |
It is worth mentioning that , If you want to use JMX Modify the runtime configuration , Must be configured isRegisterMbeans and isAllowPoolSuspension.
In fact, the more important ones are the configurations that can be modified at runtime , Just figure out what they mean , You can modify it according to your own situation .
边栏推荐
- R language plot visualization: plot visualization of two-dimensional histogram contour (basic 2D histogram contour)
- SQL is used for field data types in various databases
- Analysis of China's medical device industry development environment (PEST) in 2021: the awareness of medical care is enhanced, and the demand for medical device products is also rising [figure]
- R语言plotly可视化:plotly可视化二维直方图等高线图(Basic 2D Histogram Contour)
- 最新数据挖掘赛事方案梳理!
- Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
- PostgreSQL change table owner
- 网络安全检测与防范 测试题(五)
- 利尔达蓝牙空调接收器方案助力打造更舒适的公路生活
- Guangzhou Sinovel interactive VR panorama brings development to all walks of life
猜你喜欢

Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system
![[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code](/img/ef/a26127284fe57ac049a4313d89cf97.png)
[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code

What is an operator?

Cutting feet to fit shoes - talking about the ramp reconstruction on the track

什么是算子?
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2

One night I worked as an XPath Terminator: XPath Helper Plus

最新数据挖掘赛事方案梳理!
![Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]](/img/93/fd2cfa315c2f6d232078f7b20a7eb1.jpg)
Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]

如何快速关闭8080端口
随机推荐
Analysis on policy, output and market scale of China's natural gas hydrogen production industry in 2020 [figure]
TCP/IP 测试题(一)
Analysis on planting area, output and import of sugarcane in Guangxi in 2021: the output of sugarcane in Guangxi accounts for 68.56% of the total output of sugarcane in China [figure]
GenICam GenTL 标准 ver1.5(1)
Many varieties of EA can be used
TCP/IP 测试题(二)
Can GoogleSEO only do content without external chain? (e6zzseo)
Process of vacuum and vacuum full
PostgreSQL user role permissions
TCP/IP 测试题(三)
Redis cache preheating & avalanche & breakdown & penetration
Genicam gentl standard ver1.5 (1)
一、HikariCP获取连接流程源码分析一
LeetCode-101-对称二叉树
Electronic basic project construction & communication between main thread and rendering thread
Is it safe to open an account with flush?
Apifox simple understanding -- the integrator of web side testing
请问通达信开户安全吗?
One night I worked as an XPath Terminator: XPath Helper Plus
请问同花顺开户安全吗?