明显的死锁 c3p0 问题

Apparent Deadlock c3p0 issue

我对 C3P0 APPARENT DEAD 有疑问。我在这里查看了许多其他相关问题,但无法解决问题。如果有人可以提出任何可能的解决方案,将不胜感激!

c3p0 版本:c3p0-0.9.5.2

c3p0配置xml文件

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUrl"
        value="jdbc:oracle:thin:@transport-crash-ora-tst.cee.wisc.edu:1521:DTCRDBT" />
    <property name="user" value="transdev" />
    <property name="password" value="Its23" />
    <property name="maxPoolSize" value="10" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="5" />
    <property name="statementCacheNumDeferredCloseThreads" value="1"></property>
</bean>

控制台视图中的消息

[localhost-startStop-1] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
[localhost-startStop-1] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 72r5me9i3xucoj6ds3mi|10319844, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 72r5me9i3xucoj6ds3mi|10319844, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@transport-crash-ora-tst.cee.wisc.edu:1521:DTCRDBT, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 1, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
[localhost-startStop-1] WARN com.mchange.v2.resourcepool.BasicResourcePool - Bad pool size config, start 3 < min 5. Using 5 as start.
[C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-AdminTaskTimer] WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@7bd1346f -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
[C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-AdminTaskTimer] WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@7bd1346f -- APPARENT DEADLOCK!!! Complete Status: 
Managed Threads: 3
Active Threads: 3
Active Tasks: 
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@342bcf5e
        on thread: C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#2
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@46abe7f8
        on thread: C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#1
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@5d53fa5
        on thread: C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#0
Pending Tasks: 
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3ebf49a7
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@54043011
Pool thread stack traces:
Thread[C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#2,5,main]
    java.net.PlainSocketImpl.socketConnect(Native Method)
    java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    java.net.Socket.connect(Socket.java:589)
    oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
    oracle.net.nt.ConnOption.connect(ConnOption.java:133)
    oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
    oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
    oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
    oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
    oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
    oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
    oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
    oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
    com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
    com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Thread[C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#0,5,main]
    java.net.PlainSocketImpl.socketConnect(Native Method)
    java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    java.net.Socket.connect(Socket.java:589)
    oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
    oracle.net.nt.ConnOption.connect(ConnOption.java:133)
    oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
    oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
    oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
    oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
    oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
    oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
    oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
    oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
    com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
    com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Thread[C3P0PooledConnectionPoolManager[identityToken->72r5me9i3xucoj6ds3mi|10319844]-HelperThread-#1,5,main]
    java.net.PlainSocketImpl.socketConnect(Native Method)
    java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    java.net.Socket.connect(Socket.java:589)
    oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
    oracle.net.nt.ConnOption.connect(ConnOption.java:133)
    oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
    oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
    oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
    oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
    oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
    oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
    oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
    oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
    com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
    com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
    com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

尝试从您的 DBMS 获取连接的线程既没有成功,也没有因异常而失败。他们只是冻结。这是您需要调试的问题。这可能是某种网络/防火墙问题。例如,在 AWS 上,尝试连接到未配置安全组以允许连接的机器或服务通常会导致此类挂起。

首先要做的是确保您可以使用 DriverManager.getConnection() 从应用所在的任何地方进行连接。

(如果你愿意,你可以在你的bean xml中暂时将"com.mchange.v2.c3p0.ComboPooledDataSource"更改为"com.mchange.v2.c3p0.DriverManagerDataSource",然后看看"work"。性能会很差,因为 DriverManagerDataSource 没有池化,但您可以看到在尝试获取连接时是否所有或部分客户端线程挂起。)

如果您的应用程序通常能够获取连接,但它们偶尔会像这样挂起,并且您无法解决挂起问题,您可以尝试使用两个 c3p0 配置属性来解决它:

maxAdministrativeTaskTime 让你设置一个超时时间,之后 c3p0 的线程池将尝试中断()冻结的任务

numHelperThreads 允许您增加在开始看到 APPARENT DEADLOCK 消息之前必须被冻结捕获的线程数。