1

开启PoolSweeper

tomcat-jdbc-8.5.11-sources.jar!/org/apache/tomcat/jdbc/pool/PoolProperties.java

@Override
    public boolean isPoolSweeperEnabled() {
        boolean timer = getTimeBetweenEvictionRunsMillis()>0;
        boolean result = timer && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0);
        result = result || (timer && getSuspectTimeout()>0);
        result = result || (timer && isTestWhileIdle() && getValidationQuery()!=null);
        result = result || (timer && getMinEvictableIdleTimeMillis()>0);
        return result;
    }

参数

spring.datasource.tomcat.initial-size=10
spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.max-idle=50
spring.datasource.tomcat.min-idle=10
spring.datasource.tomcat.time-between-eviction-runs-millis=30000
spring.datasource.tomcat.min-evictable-idle-time-millis=60000
spring.datasource.tomcat.validation-query=select 1
spring.datasource.tomcat.validation-interval=30000
spring.datasource.tomcat.remove-abandoned=true
spring.datasource.tomcat.remove-abandoned-timeout=60
spring.datasource.tomcat.log-abandoned=true
spring.datasource.tomcat.abandon-when-percentage-full=50
spring.datasource.tomcat.jdbc-interceptors=ResetAbandonedTimer
spring.datasource.tomcat.suspect-timeout=60

或者

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://192.168.99.100:5432/postgres
    username: postgres
    password: postgres
    tomcat:
      initial-size: 10
      max-active: 100
      ## when pool sweeper is enabled, extra idle connection will be closed
      max-idle: 50
      ## when idle connection > min-idle, poolSweeper will start to close
      min-idle: 10
      # PoolSweeper run interval
      time-between-eviction-runs-millis: 30000
      remove-abandoned: true
      # how long a connection should return,if not return regard as leak connection
      remove-abandoned-timeout: 60
      # how log a connection should return, or regard as probably leak connection
      suspect-timeout: 60
      log-abandoned: true
      abandon-when-percentage-full: 50
      # idle connection idle time before close
      min-evictable-idle-time-millis: 60000
      validation-query: select 1
      validation-interval: 30000
      jdbc-interceptors: ResetAbandonedTimer;ConnectionState;SlowQueryReport(threshold=10)

doc


想获取最新内容,请关注微信公众号

图片描述


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...