0
對於具有多線程的獨立jar(spring批處理),我得到了以下配置的關閉連接問題。已關閉的連接:獨立jvm上的tomcat數據源(org.apache.tomcat.jdbc.pool.DataSource)
堆棧跟蹤:
Dec 07, 2015 9:57:20 AM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
WARNING: Connection has been abandoned PooledConnection[[email protected]]:java.lang.Exception
at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1052)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:704)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:633)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:186)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1108)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1173)
at org.springframework.jdbc.object.StoredProcedure.execute(StoredProcedure.java:142)
at com.abcd.package.dao.proc.BaseStoredProc.executeStoredProc(BaseStoredProc.java:81)
at com.abcd.package.dao.BaseDAO.execute(BaseDAO.java:31)
配置:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="30" />
<property name="maxIdle" value="30" />
<property name="maxActive" value="100"></property>
<property name="maxWait" value="10000"></property>
<property name="testWhileIdle" value="true"></property>
<property name="validationQuery" value="select 1 from dual"/>
<property name="validationQueryTimeout" value="1"></property>
<property name="logAbandoned" value="true"/> <!-- Temp -->
<property name="removeAbandoned" value="true"></property>
<property name="removeAbandonedTimeout" value="10"></property>
<property name="jdbcInterceptors" value="org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor(queryTimeout=8)"></property>
<!-- Added below 11/20 - LT observation -->
<property name="testOnBorrow" value="true"></property>
<property name="timeBetweenEvictionRunsMillis" value="5000"></property> <!-- 10000 -->
</bean>