当前位置:网站首页>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 .
边栏推荐
- Apifox simple understanding -- the integrator of web side testing
- PostgreSQL division considerations
- Comparison rules of strings in JS
- Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
- Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
- 利尔达蓝牙空调接收器方案助力打造更舒适的公路生活
- Current situation and development suggestions of China's green PPP project industry: the investment scale is expanding, and the existing problems need to be improved to further promote the healthy dev
- JS some small problems about adding and accessing values to arrays
- mysql视图讲解
- QQ robot official plug-in loading configuration method [beta2 version]
猜你喜欢

最新数据挖掘赛事方案梳理!

ECS 7-day practical training camp (Advanced route) -- day04 -- build a portal using ECs and polardb
![QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]](/img/25/298dc7b79dddd05914d5f3ba070555.png)
QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]

LeetCode-78-子集

Sorting out the latest data mining competition scheme!

什么是算子?

How to quickly close port 8080

利尔达蓝牙空调接收器方案助力打造更舒适的公路生活

What is an operator?

Can GoogleSEO only do content without external chain? (e6zzseo)
随机推荐
JVM | runtime data area (heap space)
LeetCode-101-对称二叉树
Current situation and development suggestions of China's green PPP project industry: the investment scale is expanding, and the existing problems need to be improved to further promote the healthy dev
Idea common plug-ins
想知道新股民怎样炒股票开户?在线开户安全么?
TCP/IP 测试题(四)
网络安全检测与防范 练习题(三)
Google cloud SSH enable root password login
请问同花顺开户安全吗?
ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
谈谈CNN中的位置和尺度问题
Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system
Guangzhou Sinovel interactive VR panorama brings development to all walks of life
Process of vacuum and vacuum full
Shell jump loop shift parameter left use of function
Network security detection and prevention test questions (4)
云上弹性高性能计算,支持生命科学产业高速发展、降本增效
mysql my. Understanding CNF depends on configuration
QQ robot: self forbidden words management of group members [latest beta2 version]
华为发布两大昇腾计划 推动AI人才发展和科研创新