封闭连接:独立jvm上的tomcat数据源(org.apache.tomcat.jdbc.pool.DataSource)

时间:2015-12-07 15:34:31

标签: java tomcat jdbc

我正在通过以下配置为我的独立jar(弹簧批)进行多线程连接问题。

堆栈追踪:

Dec 07, 2015 9:57:20 AM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
    WARNING: Connection has been abandoned PooledConnection[oracle.jdbc.driver.T4CConnection@617da8db]: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>

1 个答案:

答案 0 :(得分:0)

Exception表示您的代码不会将Connection返回到池中(通过关闭它)。

stacktrace的底部显示您从池中获取该连接的位置

com.abcd.package.dao.proc.BaseStoredProc.executeStoredProc(BaseStoredProc.java:81) at 

也许最后错过了关闭连接?