Druid连接池默认配置和坑

一、公司默认配置

  ds_0: !!com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://{host}:{port}/{schema}
    username: username
    password: password
    connectionProperties: config.decrypt=true
    filters: mergeStat,config,slf4j
    initialSize: 1
    maxActive: 20
    minIdle: 1
    maxWait: 6000
    validationQuery: SELECT 1 FROM DUAL
    testOnBorrow: false
    testOnReturn: false
    testWhileIdle: true
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 25200000
    poolPreparedStatements: true
    maxPoolPreparedStatementPerConnectionSize: 20
    logAbandoned: true
    removeAbandoned: true
    removeAbandonedTimeout: 1800
    removeAbandonedTimeoutMillis: 1800000

二、网上推荐配置

参考:https://www.jianshu.com/p/e75d73129f51

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        init-method="init" destroy-method="close">
        
        <property name="url" value="${jdbc_url}" />
        <property name="username" value="${jdbc_user}" />
        <property name="password" value="${jdbc_password}" />

        
        <property name="initialSize" value="5" />
        <property name="minIdle" value="5" />
        <property name="maxActive" value="10" />
        
        <property name="maxWait" value="10000" />

        
        <property name="timeBetweenEvictionRunsMillis" value="600000" />
        
        <property name="minEvictableIdleTimeMillis" value="300000" />
        
        <property name="testOnBorrow" value="false" />
        
        <property name="testOnReturn" value="false" />
        
        <property name="testWhileIdle" value="true" />
        
        <property name="validationQuery" value="select 1 from dual" />
        
        

        
        <property name="keepAlive" value="true" />  

        
        <property name="removeAbandoned" value="true" /> 
        
        <property name="removeAbandonedTimeout" value="80"/>
        
        <property name="logAbandoned" value="true" />

        
        <property name="connectionProperties"
            value="oracle.net.CONNECT_TIMEOUT=2000;oracle.jdbc.ReadTimeout=10000">property>

        
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
            value="20" />   

        
        

        <property name="proxyFilters">
            <list>
                <ref bean="log-filter" />
                <ref bean="stat-filter" />
            list>
        property>
        
        <property name="timeBetweenLogStatsMillis" value="120000" />
    bean>

三、关于testOnBorrow=false的解析

DBCP连接池TestOnBorrow的坑

数据连接池默认配置带来的坑testOnBorrow=false,cloes_wait 终于解决了

 

转载于:https://www.cnblogs.com/yeahwell/p/9252931.html

你可能感兴趣的:(Druid连接池默认配置和坑)