我正在开发一个 Spring-Batch,其中我使用嵌入式数据源(Apache Commons DBCP 1.3)、用于 BD2 数据库的 JDBC3 db2jcc.jar 和 JDK1.5。我知道 DBCP2.x 已经发布,但由于现有系统 (JDK 1.5),我现在无法升级。
数据库配置:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="****"/>
<property name="username" value="***"/>
<property name="password" value="****"/>
<property name="initialSize" value="5"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="30000"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="validationQuery" value="select 1 from sysibm.sysdummy1"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
</bean>
我注意到如果我将 validationQuery 属性与 testOnBorrow、testOnReturn 和 testWhileIdle 一起使用,过程需要 3 倍的时间才能完成。
在对此进行分析时,我发现在 tomcat JDBC 连接池中有一个属性“validationInterval”。
我的问题:
1) 有什么办法可以在 DBCP1.3 中设置一个 validationInterval,这样它就不会一直验证连接,而是在指定的时间段之后
2) 如果我不使用 validationQuery,我可能会遇到什么问题吗?
3) 如果没有提供validationQuery,DBCP1.3将如何验证连接?
[编辑]:
这是遵循 Nitin 建议后的测试结果:
使用以前的配置运行 1: 总耗时 - 74 秒
Run 2 Configurations: set testOnBorrow=true, testOnReturn=false, testWhileIdle=false
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="****"/>
<property name="username" value="***"/>
<property name="password" value="****"/>
<property name="initialSize" value="5"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="validationQuery" value="select 1 from sysibm.sysdummy1"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="false"/>
</bean>
总耗时 47 秒
然而调整“timeBetweenEvictionRunsMillis”处理时间没有太大变化,但我决定将其设置为 30 分钟
最佳答案
1)不,试试
testOnBorrow=真
testOnReturn=假
testWhileIdle=假
2)
您可能会因为逃避验证而获得陈旧(损坏)的连接。但是,您可以“调整”timeBetweenEvictionRunsMillis ...该线程每 5 秒执行一次以驱逐空闲连接
3)
如果没有 DBCP 1.3 中的 validationQuery,则无法验证连接
关于java - DBCP 1.3 验证查询性能下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37524168/