日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

hikaripool连接保持_springboot2的hikari数据库连接池默认配置

發(fā)布時間:2025/4/16 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hikaripool连接保持_springboot2的hikari数据库连接池默认配置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Spring-Boot-2.0.0-M1版本將默認的數(shù)據(jù)庫連接池從tomcat jdbc pool改為了hikari,這里主要研究下hikari的默認配置

spring-configuration-metadata.json

spring-boot-autoconfigure-2.0.0.M7.jar!/META-INF/spring-configuration-metadata.json

{

"sourceType": "org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari",

"name": "spring.datasource.hikari",

"sourceMethod": "dataSource(org.springframework.boot.autoconfigure.jdbc.DataSourceProperties)",

"type": "com.zaxxer.hikari.HikariDataSource"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.allow-pool-suspension",

"type": "java.lang.Boolean"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.auto-commit",

"type": "java.lang.Boolean"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.catalog",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.connection-init-sql",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.connection-test-query",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.connection-timeout",

"type": "java.lang.Long"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.data-source-class-name",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.data-source-j-n-d-i",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.data-source-properties",

"type": "java.util.Properties"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.driver-class-name",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.health-check-properties",

"type": "java.util.Properties"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.health-check-registry",

"type": "java.lang.Object"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.idle-timeout",

"type": "java.lang.Long"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"deprecated": true,

"name": "spring.datasource.hikari.initialization-fail-fast", //initializationFailTimeout > 0

"type": "java.lang.Boolean",

"deprecation": {}

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.initialization-fail-timeout",

"type": "java.lang.Long"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.isolate-internal-queries",

"type": "java.lang.Boolean"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.jdbc-url",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"deprecated": true,

"name": "spring.datasource.hikari.jdbc4-connection-test", //廢棄

"type": "java.lang.Boolean",

"deprecation": {}

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.leak-detection-threshold",

"type": "java.lang.Long"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.login-timeout", //在HikariDataSource及PoolBase中

"type": "java.lang.Integer"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.max-lifetime",

"type": "java.lang.Long"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.maximum-pool-size",

"type": "java.lang.Integer"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.metric-registry",

"type": "java.lang.Object"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.metrics-tracker-factory",

"type": "com.zaxxer.hikari.metrics.MetricsTrackerFactory"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.minimum-idle",

"type": "java.lang.Integer"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.password",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.pool-name",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.read-only",

"type": "java.lang.Boolean"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.register-mbeans",

"type": "java.lang.Boolean"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.scheduled-executor",

"type": "java.util.concurrent.ScheduledExecutorService"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"deprecated": true,

"name": "spring.datasource.hikari.scheduled-executor-service",

"type": "java.util.concurrent.ScheduledThreadPoolExecutor",

"deprecation": {}

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.schema",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.transaction-isolation", //transactionIsolationName

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.username",

"type": "java.lang.String"

},

{

"sourceType": "com.zaxxer.hikari.HikariDataSource",

"name": "spring.datasource.hikari.validation-timeout",

"type": "java.lang.Long"

},

HikariConfig

HikariCP-2.7.6-sources.jar!/com/zaxxer/hikari/HikariConfig.java

@SuppressWarnings({"SameParameterValue", "unused"})

public class HikariConfig implements HikariConfigMXBean

{

private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class);

private static final char[] ID_CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

private static final long CONNECTION_TIMEOUT = SECONDS.toMillis(30);

private static final long VALIDATION_TIMEOUT = SECONDS.toMillis(5);

private static final long IDLE_TIMEOUT = MINUTES.toMillis(10);

private static final long MAX_LIFETIME = MINUTES.toMillis(30);

private static final int DEFAULT_POOL_SIZE = 10;

//......

/**

* Default constructor

*/

public HikariConfig()

{

dataSourceProperties = new Properties();

healthCheckProperties = new Properties();

minIdle = -1;

maxPoolSize = -1;

maxLifetime = MAX_LIFETIME;

connectionTimeout = CONNECTION_TIMEOUT;

validationTimeout = VALIDATION_TIMEOUT;

idleTimeout = IDLE_TIMEOUT;

initializationFailTimeout = 1;

isAutoCommit = true;

String systemProp = System.getProperty("hikaricp.configurationFile");

if (systemProp != null) {

loadProperties(systemProp);

}

}

@Override

public void setConnectionTimeout(long connectionTimeoutMs)

{

if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");

if (connectionTimeoutMs == 0) {

this.connectionTimeout = Integer.MAX_VALUE;

}

else if (connectionTimeoutMs < 250) {

throw new IllegalArgumentException("connectionTimeout cannot be less than 250ms");

}

else {

this.connectionTimeout = connectionTimeoutMs;

}

}

@Override

public void setIdleTimeout(long idleTimeoutMs)

{

if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");

if (idleTimeoutMs < 0) {

throw new IllegalArgumentException("idleTimeout cannot be negative");

}

this.idleTimeout = idleTimeoutMs;

}

@Override

public void setMaximumPoolSize(int maxPoolSize)

{

if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");

if (maxPoolSize < 1) {

throw new IllegalArgumentException("maxPoolSize cannot be less than 1");

}

this.maxPoolSize = maxPoolSize;

}

@Override

public void setMinimumIdle(int minIdle)

{

if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");

if (minIdle < 0) {

throw new IllegalArgumentException("minimumIdle cannot be negative");

}

this.minIdle = minIdle;

}

@Override

public void setValidationTimeout(long validationTimeoutMs)

{

if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");

if (validationTimeoutMs < 250) {

throw new IllegalArgumentException("validationTimeout cannot be less than 250ms");

}

this.validationTimeout = validationTimeoutMs;

}

public void validate()

{

if (poolName == null) {

poolName = generatePoolName();

}

else if (isRegisterMbeans && poolName.contains(":")) {

throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX");

}

// treat empty property as null

catalog = getNullIfEmpty(catalog);

connectionInitSql = getNullIfEmpty(connectionInitSql);

connectionTestQuery = getNullIfEmpty(connectionTestQuery);

transactionIsolationName = getNullIfEmpty(transactionIsolationName);

dataSourceClassName = getNullIfEmpty(dataSourceClassName);

dataSourceJndiName = getNullIfEmpty(dataSourceJndiName);

driverClassName = getNullIfEmpty(driverClassName);

jdbcUrl = getNullIfEmpty(jdbcUrl);

// Check Data Source Options

if (dataSource != null) {

if (dataSourceClassName != null) {

LOGGER.warn("{} - using dataSource and ignoring dataSourceClassName.", poolName);

}

}

else if (dataSourceClassName != null) {

if (driverClassName != null) {

LOGGER.error("{} - cannot use driverClassName and dataSourceClassName together.", poolName);

// NOTE: This exception text is referenced by a Spring Boot FailureAnalyzer, it should not be

// changed without first notifying the Spring Boot developers.

throw new IllegalStateException("cannot use driverClassName and dataSourceClassName together.");

}

else if (jdbcUrl != null) {

LOGGER.warn("{} - using dataSourceClassName and ignoring jdbcUrl.", poolName);

}

}

else if (jdbcUrl != null || dataSourceJndiName != null) {

// ok

}

else if (driverClassName != null) {

LOGGER.error("{} - jdbcUrl is required with driverClassName.", poolName);

throw new IllegalArgumentException("jdbcUrl is required with driverClassName.");

}

else {

LOGGER.error("{} - dataSource or dataSourceClassName or jdbcUrl is required.", poolName);

throw new IllegalArgumentException("dataSource or dataSourceClassName or jdbcUrl is required.");

}

validateNumerics();

if (LOGGER.isDebugEnabled() || unitTest) {

logConfiguration();

}

}

private void validateNumerics()

{

if (maxLifetime != 0 && maxLifetime < SECONDS.toMillis(30)) {

LOGGER.warn("{} - maxLifetime is less than 30000ms, setting to default {}ms.", poolName, MAX_LIFETIME);

maxLifetime = MAX_LIFETIME;

}

if (idleTimeout + SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) {

LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", poolName);

idleTimeout = 0;

}

if (idleTimeout != 0 && idleTimeout < SECONDS.toMillis(10)) {

LOGGER.warn("{} - idleTimeout is less than 10000ms, setting to default {}ms.", poolName, IDLE_TIMEOUT);

idleTimeout = IDLE_TIMEOUT;

}

if (leakDetectionThreshold > 0 && !unitTest) {

if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) {

LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName);

leakDetectionThreshold = 0;

}

}

if (connectionTimeout < 250) {

LOGGER.warn("{} - connectionTimeout is less than 250ms, setting to {}ms.", poolName, CONNECTION_TIMEOUT);

connectionTimeout = CONNECTION_TIMEOUT;

}

if (validationTimeout < 250) {

LOGGER.warn("{} - validationTimeout is less than 250ms, setting to {}ms.", poolName, VALIDATION_TIMEOUT);

validationTimeout = VALIDATION_TIMEOUT;

}

if (maxPoolSize < 1) {

maxPoolSize = (minIdle <= 0) ? DEFAULT_POOL_SIZE : minIdle;

}

if (minIdle < 0 || minIdle > maxPoolSize) {

minIdle = maxPoolSize;

}

}

}

可以看到在set方法添加了參數(shù)校驗,同時在configuration的構(gòu)造器以及getConnection方法中也調(diào)用了validate方法

public HikariDataSource(HikariConfig configuration)

{

configuration.validate();

configuration.copyStateTo(this);

this.seal();

LOGGER.info("{} - Starting...", configuration.getPoolName());

pool = fastPathPool = new HikariPool(this);

LOGGER.info("{} - Start completed.", configuration.getPoolName());

}

/** {@inheritDoc} */

@Override

public Connection getConnection() throws SQLException

{

if (isClosed()) {

throw new SQLException("HikariDataSource " + this + " has been closed.");

}

if (fastPathPool != null) {

return fastPathPool.getConnection();

}

// See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java

HikariPool result = pool;

if (result == null) {

synchronized (this) {

result = pool;

if (result == null) {

validate();

LOGGER.info("{} - Starting...", getPoolName());

try {

pool = result = new HikariPool(this);

this.seal();

}

catch (PoolInitializationException pie) {

if (pie.getCause() instanceof SQLException) {

throw (SQLException) pie.getCause();

}

else {

throw pie;

}

}

LOGGER.info("{} - Start completed.", getPoolName());

}

}

}

return result.getConnection();

}

springboot的autoconfig是采用BeanUtils的反射來初始化HikariDataSource,走的是默認構(gòu)造器,因此校驗就依賴set方法以及后續(xù)的getConnection方法。

PoolBase.setLoginTimeout

HikariCP-2.7.6-sources.jar!/com/zaxxer/hikari/pool/PoolBase.java

/**

* Set the loginTimeout on the specified DataSource.

*

* @param dataSource the DataSource

*/

private void setLoginTimeout(final DataSource dataSource)

{

if (connectionTimeout != Integer.MAX_VALUE) {

try {

dataSource.setLoginTimeout(Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout)));

}

catch (Throwable e) {

LOGGER.info("{} - Failed to set login timeout for data source. ({})", poolName, e.getMessage());

}

}

}

這個在初始化的時候設(shè)定了loginTimeout,初始值為Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout))

小結(jié)

springboot的HikariDataSource默認配置的默認值如下

name

構(gòu)造器默認值

默認配置validate之后的值

validate重置

minIdle

-1

10

minIdle<0或者minIdle>maxPoolSize,則被重置為maxPoolSize

maxPoolSize

-1

10

如果maxPoolSize小于1,則會被重置。當(dāng)minIdle<=0被重置為DEFAULT_POOL_SIZE則為10;如果minIdle>0則重置為minIdle的值

maxLifetime

MINUTES.toMillis(30) = 1800000

1800000

如果不等于0且小于30秒則會被重置回30分鐘

connectionTimeout

SECONDS.toMillis(30) = 30000

30000

如果小于250毫秒,則被重置回30秒

validationTimeout

SECONDS.toMillis(5) = 5000

5000

如果小于250毫秒,則會被重置回5秒

loginTimeout

10

30

Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout)),為connectionTimeout+500ms轉(zhuǎn)為秒數(shù)取整 與 1 取最大者

idleTimeout

MINUTES.toMillis(10) = 600000

600000

如果idleTimeout+1秒>maxLifetime 且 maxLifetime>0,則會被重置為0;如果idleTimeout!=0且小于10秒,則會被重置為10秒

leakDetectionThreshold

0

0

如果大于0且不是單元測試,則進一步判斷:(leakDetectionThreshold < SECONDS.toMillis(2) or (leakDetectionThreshold > maxLifetime && maxLifetime > 0),會被重置為0 . 即如果要生效則必須>0,而且不能小于2秒,而且當(dāng)maxLifetime > 0時不能大于maxLifetime

initializationFailTimeout

1

1

-

isAutoCommit

true

true

-

isReadOnly

false

fasle

-

isAllowPoolSuspension

false

false

-

isIsolateInternalQueries

false

false

-

isRegisterMbeans

false

false

-

sealed

false

true

運行啟動后這個標(biāo)志為true,表示不再運行修改

poolName

null

HikariPool-1

-

catalog

null

null

-

connectionInitSql

null

null

-

connectionTestQuery

null

null

-

dataSourceClassName

null

null

-

schema

null

null

-

transactionIsolationName

null

null

-

dataSource

null

null

-

dataSourceProperties

{}

{}

-

threadFactory

null

null

-

scheduledExecutor

null

null

-

metricsTrackerFactory

null

null

-

metricRegistry

null

null

-

healthCheckRegistry

null

null

-

healthCheckProperties

{}

{}

-

doc

總結(jié)

以上是生活随笔為你收集整理的hikaripool连接保持_springboot2的hikari数据库连接池默认配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中国美女一级看片 | 国产破处av| 国产又色又爽无遮挡免费 | 美女黄色av | 蜜臀一区| 日韩av中文字幕在线 | 色屁屁一区二区三区视频 | 亚洲一二区 | 性感美女毛片 | 九九精品在线视频 | 深夜视频在线 | 老汉色老汉首页av亚洲 | 青青草成人免费视频 | 日韩在线免费视频观看 | 久久传媒 | 91精品国产乱码久久久久久久久 | 欧美三级在线 | 精品国产成人亚洲午夜福利 | 日本色视频 | 国产成人精品久久二区二区 | 国产suv精品一区二区883 | 国产精品专区在线观看 | 久草久热 | av一级网站 | 97精品人妻麻豆一区二区 | 给我看免费高清在线观看 | 亚洲一区二区三区三州 | 久久精品99久久 | 精品黄色片| 久草成人在线视频 | 亚洲人视频在线观看 | 久久久久一 | 日本五十熟hd丰满 | 黄色一级片av | 337p嫩模大胆色肉噜噜噜 | 亚洲欧美日韩一区 | 91人妻一区二区三区 | 97精品视频 | 美腿丝袜亚洲综合 | 亚洲一区二区日本 | 床戏高潮做进去大尺度视频网站 | 男女做网站 | 337p亚洲欧洲色噜噜噜 | 国产一区二区三区四 | 国产日本在线播放 | 久久久人人人 | 免费观看毛片网站 | 直接看av的网站 | 国产99精品| 成人欧美一区二区三区黑人一 | 妓院一钑片免看黄大片 | 91福利在线免费观看 | 亚洲精品国产一区二区 | 国产乱码精品一区二区三区忘忧草 | 青春草av | 日本黄色性视频 | 亚洲国产成人精品91久久久 | 亚洲欧洲精品一区二区 | 日本久久亚洲 | 狂野欧美 | 日日摸日日添日日躁av | 97人妻人人澡人人爽人人精品 | 久久久久性 | 国产8区 | 少妇精品高潮欲妇又嫩中文字幕 | 午夜av中文字幕 | 操操操插插插 | 日本亚洲免费 | 九色porny原创自拍 | 亚洲第一色网站 | 午夜精品久久久久久久99热浪潮 | 青青草娱乐在线 | 精品少妇一区 | 欧美一区日韩一区 | 老司机在线观看视频 | 日本一区二区三区四区五区 | 少妇做爰免费视频播放 | 91手机视频 | 丁香六月激情 | 日韩一区二区三区网站 | 国产调教一区 | 亚洲精品视频在线免费 | 精品成在人线av无码免费看 | 91人妻一区二区三区 | 国产剧情一区在线 | 欧美成人h版 | 国产看片网站 | 色玖玖| 美女擦边视频 | 免费一级片视频 | 日韩理论在线 | 88国产精品视频一区二区三区 | 久草免费资源站 | 精品一区二区三区电影 | 亚洲色图校园春色 | 欧美黄色一级片视频 | 国内三级视频 | 成年人免费在线观看网站 | 国产成人免费网站 |