1

我正在使用 C3p0 连接池,并且在我的服务器中观察到以下异常。

 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@ed866f -- APPARENT DEADLOCK!!! Complete Status:
    Managed Threads: 1
    Active Threads: 1
    Active Tasks:
        com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@995ec2 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
    Pending Tasks: 
            com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@11c3ceb
            com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@e392ed
            com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@c33853
            com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@a6f77d
            com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1c25bfc
            com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@12534a9
            com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@1a4564c
Pool thread stack traces:
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
                oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1338)
                com.mchange.v2.c3p0.impl.NewPooledConnection.cleanupUncachedStatements(NewPooledConnection.java:651)
                com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:539)
                com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
                com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
               com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

我的配置是

<property name="initialPoolSize" value="1" />
    <property name="minPoolSize" value="1" />
    <property name="maxPoolSize" value="20" />
    <property name="maxIdleTime" value="240" />
    <property name="checkoutTimeout" value="60000" />
    <property name="acquireRetryAttempts" value="0" />
    <property name="acquireRetryDelay" value="1000" />
    <property name="debugUnreturnedConnectionStackTraces" value="true" />
    <property name="unreturnedConnectionTimeout" value="300" />
    <property name="numHelperThreads" value="1" />
    <property name="preferredTestQuery" value="SELECT 1 FROM DUAL" />

经过一番搜索后,我发现了以下线程。 https://forum.hibernate.org/viewtopic.php?t=947246

建议禁用语句缓存以避免此问题。但在我的配置中,我没有启用语句缓存(maxStatements,maxStatementsPerConnection 默认为 0)。

请提出任何替代方案。

4

1 回答 1

4

不要将 numHelperThreads 设置为 1。

如果将 numHelperThreads 设置为 1,任何慢速任务都会触发一个明显的死锁。c3p0 依赖于一个内部线程池。一个线程不创建池。让 numHelperThreads 至少具有其默认值 3。

具体来说,您的堆栈跟踪中发生的事情是连接池尝试关闭()连接需要很长时间,出于某种原因。这里可能存在一个真正的问题,如果这种情况经常发生,但它可能只是偶尔的缓慢操作,一个合理大小的线程池只会处理并耸耸肩。

祝你好运!

于 2012-11-08T08:16:53.347 回答