[JAVA] Use Hikari connection pool in springBoot

Uncle Cthulhu 2022-11-24 21:24:57 阅读数:337

javausehikariconnectionpool

1. Configuration

spring.datasource.type=com.zaxxer.hikari.HikariDataSourcespring.datasource.hikari.minimum-idle=5spring.datasource.hikari.maximum-pool-size=15spring.datasource.hikari.auto-commit=truespring.datasource.hikari.idle-timeout=60000spring.datasource.hikari.pool-name=DatebookHikariCPspring.datasource.hikari.max-lifetime=300000spring.datasource.hikari.connection-timeout=30000spring.datasource.hikari.connection-test-query=SELECT 1

The configuration is for reference only and can be modified according to your needs;

After startup

2019-03-06 update: yaml

 datasource:hikari:#autocommitauto-commit: trueconnection-test-query: SELECT 1#Waiting for the maximum time (milliseconds) for the connection pool to allocate a connection. A SQLException will occur if the connection is not available for more than this time. Default: 30 seconds -->connection-timeout: 30000# The maximum duration (in milliseconds) of a connection idle state, the timeout will be released (retired), default: 10 minutes -->idle-timeout: 600000#The lifetime of a connection (in milliseconds), if it times out and is not used, it will be released (retired), default: 30 minutes,#It is recommended to set 30 seconds less than the database timeout, refer to the MySQL wait_timeout parameter (show variables like '%timeout%';) -->max-lifetime: 620000#The maximum number of connections allowed in the connection pool.Default value: 10; recommended formula: ((core_count * 2) + effective_spindle_count) -->maximum-pool-size: 30#The minimum number of idle connections maintained in the poolminimum-idle: 5pool-name: DatebookHikariCPread-only: falsetype: com.zaxxer.hikari.HikariDataSource

2020-04-06 After optimization is used in the project:

datasource:type: com.zaxxer.hikari.HikariDataSourcedriver-class-name: com.mysql.jdbc.Driverhikari:#autocommitauto-commit: trueconnection-test-query: SELECT 1#Waiting for the maximum time (milliseconds) for the connection pool to allocate a connection. A SQLException will occur if the connection is not available for more than this time. Default: 30 seconds -->connection-timeout: 30000# The maximum duration (in milliseconds) of a connection idle state, the timeout will be released (retired), default: 10 minutes -->idle-timeout: 300000#The lifetime of a connection (in milliseconds), if it times out and is not used, it will be released (retired), default: 30 minutesmax-lifetime: 1800000#The maximum number of connections allowed in the connection pool.Default value: 10; recommended formula: ((core_count * 2) + effective_spindle_count) -->maximum-pool-size: 20#The minimum number of idle connections maintained in the pool, if the number of idle connections in the connection pool is less than minimumIdle,#And when the total number of connections is not greater than maximumPoolSize, HikariCP will try its best to add new connections.For performance considerations, it is not recommended to set this value, but let HikariCP treat the connection pool as a fixed size, and the default minimumIdle is the same as maximumPoolSize.minimum-idle: 5pool-name: DatebookHikariCPread-only: false#Verify the valid time of the connection with the databasevalidation-timeout: 5000

copyright:author[Uncle Cthulhu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/328/202211242120378162.html