表观死锁c3p0问题

时间:2016-07-21 17:28:43

标签: spring c3p0

我遇到了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="Its2$123" />
    <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.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.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.access$700(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.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.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.access$700(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.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.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.access$700(BasicResourcePool.java:44)
    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

1 个答案:

答案 0 :(得分:0)

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

要做的第一件事是确保您可以使用DriverManager.getConnection()从应用程序所在的任何地方进行连接。

(如果你愿意,你可以在你的bean xml中临时更改&#34; com.mchange.v2.c3p0.ComboPooledDataSource&#34;到&#34; com.mchange.v2.c3p0.DriverManagerDataSource&#34;并且看看事情是否有效&#34;。性能会很差,因为DriverManagerDataSource没有汇集,但是你可以看到在尝试获取Connections时是否所有或部分客户端线程都挂起。)

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

maxAdministrativeTaskTime允许您设置超时,之后c3p0的线程池将尝试中断()冻结的任务

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