2

在我的 webapp 中,我经常遇到异常

org.hibernate.util.JDBCExceptionReporter: SQL Error: 17002, SQLState: 08006
        14 Sep 2013 12:19:10,927 [ERROR] org.hibernate.util.JDBCExceptionReporter: IO Error: Connection reset
        14 Sep 2013 12:19:10,927 [ERROR]  could not load an entity: [EntityName]
    nested exception is org.hibernate.exception.JDBCConnectionException: could not load an entity: [EntityName]

...

14 Sep 2013 12:19:10,930 [WARN]  (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) com.mchange.v1.db.sql.StatementUtils: Statement close FAILED.
java.sql.SQLRecoverableException: Closed Connection
    at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
    at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
    at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
    at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.close(OraclePreparedStatementWrapper.java:80)
    at com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.synchronousDestroyStatement(GooGooStatementCache.java:413)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.closeAll(GooGooStatementCache.java:351)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeAllCachedStatements(NewPooledConnection.java:673)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:543)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

我尝试更改 C3P0 配置,但没有帮助

这是我当前的配置:

checkoutTimeout     10000   
idleConnectionTestPeriod        0
initialPoolSize     10  
maxIdleTime     28800   
maxPoolSize     20  
minPoolSize     8   
numHelperThreads        5
testConnectionOnCheckin     true

相关代码:简单调用HibernateTemplate的get方法

Object result = getHibernateTemplate().get(entityClass, id);
return (T) result;
4

1 回答 1

2

虽然听起来你已经尝试了很多,但如果你使用的是 testConnectionOnCheckin,你应该将它与一个短的、非零的 idleConnectionTestPeriod 结合起来。为了提高性能,您还应该设置一个 preferredTestQuery。

检查不可靠的连接测试是否是您的问题的最简单方法是从 testConnectionOnCheckin 切换到 testConnectionOnCheckout(并添加一个 preferredTestQuery 以尽量减少对性能的影响)。如果这解决了您的问题,那么您知道您需要的是良好的连接测试,并且您可以切换回并使用 idleConnectionTestPeriod 的长度。如果 testConnectionOnCheckout 不能解决问题,那么它不太可能是连接测试问题。testConnectionOnCheckout 是一个非常可靠的设置。

http://www.mchange.com/projects/c3p0-0.9.5-pre4/#simple_advice_on_connection_testing http://www.mchange.com/projects/c3p0-0.9.5-pre4/#configuring_connection_testing

于 2013-09-14T13:27:29.753 回答