当前位置:网站首页>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 .
边栏推荐
- 揭秘GES超大规模图计算引擎HyG:图切分
- Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
- Solidity get quarterly time
- IDEA常用插件
- JVM|运行时数据区(堆空间)
- PHP database connection version1.1
- Network security detection and prevention test questions (4)
- What are Baidu collection skills? 2022 Baidu article collection skills
- Solidity date tool
- Ali visual AI training camp -day05- creativity day - your image recognition project
猜你喜欢

Svn introduction and Usage Summary

Process of vacuum and vacuum full

Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system

How to quickly close port 8080

Does GoogleSEO need to change the friend chain? (e6zzseo)

Record Baidu search optimization thinking analysis

What is an operator?
![2021 development status of China's cloud game industry and analysis of major service providers: Although cloud games are still in their infancy, the market prospect is huge [figure]](/img/82/84072a7b125f81363fb26ac56e9d27.jpg)
2021 development status of China's cloud game industry and analysis of major service providers: Although cloud games are still in their infancy, the market prospect is huge [figure]

Trend ea- fixed stop loss and profit per order

QQ机器人疫情查询/疫情关注等【最新beta2版本】
随机推荐
JS some small problems about adding and accessing values to arrays
QQ机器人:群成员自我禁言管理【最新beta2版本】
网络安全检测与防范 测试题(五)
QQ robot: self forbidden words management of group members [latest beta2 version]
Shell jump loop shift parameter left use of function
mysql my. Understanding CNF depends on configuration
Miner's Diary: why should I go mining on April 5, 2021
Cutting feet to fit shoes - talking about the ramp reconstruction on the track
What should I pay attention to in GoogleSEO content station optimization?
solidity获取季度时间
五、HikariCP源码分析之初始化分析二
Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
PostgreSQL change table owner
Many varieties of EA can be used
Apifox simple understanding -- the integrator of web side testing
Mail monitoring cloud script execution progress
Network security detection and prevention exercises (III)
MySQL transaction explanation
Bloom filter
Idea common plug-ins