我不知道你的版本,但在版本2.2.4中,你会发现它会抛出上述警告的原因。 (在):HikariCP
HikariConfig.class
com.zaxxer.hikari.HikariConfig
private void More ...validateNumerics()
{
Logger logger = LoggerFactory.getLogger(getClass());
if (connectionTimeout == Integer.MAX_VALUE) {
logger.warn("No connection wait timeout is set, this might cause an infinite wait.");
}
if (minIdle < 0 || minIdle > maxPoolSize) {
minIdle = maxPoolSize;
}
if (maxLifetime < 0) {
logger.error("maxLifetime cannot be negative.");
throw new IllegalArgumentException("maxLifetime cannot be negative.");
}
else if (maxLifetime > 0 && maxLifetime < TimeUnit.SECONDS.toMillis(120)) {
logger.warn("maxLifetime is less than 120000ms, using default {}ms.", MAX_LIFETIME);
maxLifetime = MAX_LIFETIME;
}
if (idleTimeout != 0 && idleTimeout < TimeUnit.SECONDS.toMillis(30)) {
logger.warn("idleTimeout is less than 30000ms, using default {}ms.", IDLE_TIMEOUT);
idleTimeout = IDLE_TIMEOUT;
}
else if (idleTimeout > maxLifetime && maxLifetime > 0) {
logger.warn("idleTimeout is greater than maxLifetime, setting to maxLifetime.");
idleTimeout = maxLifetime;
}
从此代码中,最大LifeTime至少为120000ms,使用默认值1800000ms,因此您无法将其设置为30000ms(30 * 1000)。我猜你的版本至少早于2.2.4。maxLifeTime
HikariCP
但是当你找到最新的HikariCP
版本2.7.4时。它说:“我们强烈建议设置此值,并且它应该比任何数据库或基础架构施加的连接时间限制至少少30秒。"
同一类 :HikariConfig.class
private void validateNumerics() {
if(this.maxLifetime != 0L && this.maxLifetime < TimeUnit.SECONDS.toMillis(30L)) {
LOGGER.warn("{} - maxLifetime is less than 30000ms, setting to default {}ms.", this.poolName, Long.valueOf(MAX_LIFETIME));
this.maxLifetime = MAX_LIFETIME;
}
if(this.idleTimeout + TimeUnit.SECONDS.toMillis(1L) > this.maxLifetime && this.maxLifetime > 0L) {
LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", this.poolName);
this.idleTimeout = 0L;
}
if(this.idleTimeout != 0L && this.idleTimeout < TimeUnit.SECONDS.toMillis(10L)) {
LOGGER.warn("{} - idleTimeout is less than 10000ms, setting to default {}ms.", this.poolName, Long.valueOf(IDLE_TIMEOUT));
this.idleTimeout = IDLE_TIMEOUT;
}
if(this.leakDetectionThreshold > 0L && !unitTest && (this.leakDetectionThreshold < TimeUnit.SECONDS.toMillis(2L) || this.leakDetectionThreshold > this.maxLifetime && this.maxLifetime > 0L)) {
LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", this.poolName);
this.leakDetectionThreshold = 0L;
}
if(this.connectionTimeout < 250L) {
LOGGER.warn("{} - connectionTimeout is less than 250ms, setting to {}ms.", this.poolName, Long.valueOf(CONNECTION_TIMEOUT));
this.connectionTimeout = CONNECTION_TIMEOUT;
}
if(this.validationTimeout < 250L) {
LOGGER.warn("{} - validationTimeout is less than 250ms, setting to {}ms.", this.poolName, Long.valueOf(VALIDATION_TIMEOUT));
this.validationTimeout = VALIDATION_TIMEOUT;
}
if(this.maxPoolSize < 1) {
this.maxPoolSize = this.minIdle <= 0?10:this.minIdle;
}
if(this.minIdle < 0 || this.minIdle > this.maxPoolSize) {
this.minIdle = this.maxPoolSize;
}
}
从此代码中,至少在此版本中已更新为 30000ms。maxLifeTime
因此,现在,如果要将maxLifeTime设置为30000ms,请将您的版本更新到最新版本2.7.4。HikariCP
但是,如果您使用JDK 8将HikariCP版本更新到2.7.4,我也建议您两点:
1. 将最大寿命
值设置为至少 30000ms。
2.将maxLifeTime
值设置为比mysql的wait_timeout
少几分钟(显示“%timeout%”等变量
)以避免断开连接异常。