当前位置:网站首页>Additional: brief description of hikaricp connection pool; (I didn't go deep into it, but I had a basic understanding of hikaricp connection pool)

Additional: brief description of hikaricp connection pool; (I didn't go deep into it, but I had a basic understanding of hikaricp connection pool)

2022-06-26 02:46:00 Small withered forest

explain :

(1) Why did you write this blog ?: stay 【16: Chapter two : Architecture back end project :12: To configure mybatis;( stay 【imooc-news-dev-service-user】 This micro service sub project , To configure )】 in , Our database connection pool uses HikariCP Connection pool ;;; therefore , Wrote this blog , Give a brief introduction ;

(2) The articles referenced in this blog are :

          ●【Hikari Connection pool 】, The author of this article is 【 Wang Liuliu's IT daily 】;

          ●【Spring Series of HikariCP Connection pool 】, The author of this article is 【 A Niu, programmer 】;

Catalog

One : Reference article 1:Hikari Connection pool ;

Two : Reference article 2:Spring Series of HikariCP Connection pool ;


One : Reference article 1:Hikari Connection pool ;

Reference from 【Hikari Connection pool 】, The author of this article is 【 Wang Liuliu's IT daily 】;

hikari:
   #  Connection pool name 
  pool-name: DateHikariCP
   #  Minimum number of idle connections 
  minimum-idle: 5
   #  Maximum free connection lifetime , Default 600000(10 minute )
  idle-timeout: 180000
   #  The maximum number of connections in the connection pool , Default 10
  maximum-pool-size: 10
   #  This property controls the default auto commit behavior for connections returned from the pool , The default value is :true
  auto-commit: true
   #  This property controls the maximum lifetime of connections in the pool , value 0 It means infinite life cycle , Default 1800000 namely 30 minute 
  max-lifetime: 1800000
   #  Database connection timeout , Default 30000(30 second )
  onnection-timeout: 30000
   #  Query statement to test whether the connection is available 
  connection-test-query: SELECT 1

Two : Reference article 2:Spring Series of HikariCP Connection pool ;

Reference from 【Spring Series of HikariCP Connection pool 】, The author of this article is 【 A Niu, programmer 】;


/**
*  The following three notes mean when classpath There is HikariDataSource.class, also Spring There is no configuration in the context DataSource Of bean
*  also spring.datasource.type The value of is com.zaxxer.hikari.HikariDataSource When ,SpringBoot Automatically help us choose the default connection pool is HikariDataSource
*/
@ConditionalOnClass({HikariDataSource.class})
@ConditionalOnMissingBean({DataSource.class})
@ConditionalOnProperty(name = {"spring.datasource.type"},havingValue = "com.zaxxer.hikari.HikariDataSource",matchIfMissing = true)
static class Hikari {
        Hikari() {
}

@Bean
@ConfigurationProperties(prefix = "spring.datasource.hikari")
HikariDataSource dataSource(DataSourceProperties properties) {
            HikariDataSource dataSource = (HikariDataSource)DataSourceConfiguration.createDataSource(properties, HikariDataSource.class);
            if (StringUtils.hasText(properties.getName())) {
                dataSource.setPoolName(properties.getName());
            }
            return dataSource;
        }
}
#  These four configurations are used for different data sources 
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# The following configuration items are hikari Unique configuration 
#  The maximum length of time to wait for the connection pool to allocate the connection ( millisecond ), Connections that have not been available for more than this period of time occur SQLException,  Default :30 second 
spring.datasource.hikari.connection-timeout=30000
#  Minimum connections 
spring.datasource.hikari.minimum-idle=5
#  maximum connection 
spring.datasource.hikari.maximum-pool-size=15
#  Automatic submission 
spring.datasource.hikari.auto-commit=true
#  A connection idle The maximum duration of a state ( millisecond ), Timeout is released (retired), Default :10 minute 
spring.datasource.hikari.idle-timeout=600000
#  Connection pool name 
spring.datasource.hikari.pool-name=DatebookHikariCP
#  A connected life span ( millisecond ), Time out and not used is released (retired), Default :30 minute  1800000ms, It is recommended to set the timeout less than the database 60 second 
spring.datasource.hikari.max-lifetime=28740000
spring.datasource.hikari.connection-test-query=SELECT 1

# The following is for MYSQL Configuration parameters of the driver 
#  The number of statements cached in each connection . The default value is conservative 25. It is recommended that it be set to 250-500 Between 
spring.datasource.hikari.prepStmtCacheSize = 300
#  Cached prepared SQL The maximum length of a statement , The default value is 256, But often this length is not enough 
spring.datasource.hikari.prepStmtCacheSqlLimit = 2048
#  Cache switch , If this is set to false, Neither of the above two parameters takes effect 
spring.datasource.hikari.cachePrepStmts = true
# Newer versions of  MySQL  Support prepared statements on the server side , This can provide substantial performance improvements 
spring.datasource.hikari.useServerPrepStmts = true

HikariCP Official address : https://github.com/brettwoold...

原网站

版权声明
本文为[Small withered forest]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260155132744.html