以下是我的DBCP连接池配置
<property name="maxWait" value="30000"/>
<property name="maxActive" value="100"/>
<property name="minIdle" value="0"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
<property name="defaultAutoCommit" value="true"/>
<property name="validationQuery" value="select sysdate from dual" />
<property name="testOnBorrow" value="true" />
<property name="tryRecoveryInMinutes" value="0.25" />
但是我在线程转储文件中遇到异常。
"mythread-10444" prio=10 tid=0x00007ff098de9800 nid=0x77c runnable [0x00007ff0fd289000]
java.lang.Thread.State: RUNNABLE
at oracle.jdbc.driver.T2CStatement.t2cParseExecuteDescribe(Native Method)
at oracle.jdbc.driver.T2CStatement.executeForDescribe(T2CStatement.java:703)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1498)
- locked <0x00000000e434a3c0> (a oracle.jdbc.driver.T2CConnection)
at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:406)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at org.apache.commons.dbcp.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:658)
at org.apache.commons.dbcp.PoolableConnectionFactory.validateObject(PoolableConnectionFactory.java:635)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1165)
at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:79)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
最初它工作正常,但过了一段时间我的应用程序完全挂起。能告诉我这是什么问题吗?
答案 0 :(得分:0)
该异常明确指出您的线程仍在正在运行且您的连接已锁定,而它正在忙于执行查询。
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1498)
- locked <0x00000000e434a3c0> (a oracle.jdbc.driver.T2CConnection)
我担心的是找出哪一个查询正在执行那么久(超时之前)并对其进行优化。基于异常堆栈跟踪,您正在执行DESCRIBE
,Oracle RDMS锁定该查询,并且在尝试运行另一个查询时仍然执行。
答案 1 :(得分:0)
考虑到Spring环境,您是否在Spring配置XML中正确定义了事务管理器bean?
<!-- Spring transaction manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- Spring transaction management per transactional-annotation -->
<tx:annotation-driven transaction-manager="transactionManager" />
在我的团队中,几周前我们遇到了类似的问题,没有注意到这一部分是由我们的Spring XML中的注释包装的。结果,一堆事务从未在数据库前提交。希望这会有所帮助。
答案 2 :(得分:0)
我的应用程序使用dbcp时遇到了类似的问题。事实证明连接没有正确关闭。在例外情况下,连接被泄露,因此在一段时间后导致死锁。 I have written a full explanation here