tomcat jdbc pool高级配置

开启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

  • Tomcat-JDBC-连接池配置

  • configuring-jdbc-pool-high-concurrency


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

tomcat jdbc pool高级配置_第1张图片
qrcode_for_gh_121b87c80448_258.jpg

你可能感兴趣的:(tomcat jdbc pool高级配置)