关于RefurbishCheckinResourceTask,getConnection()的c3p0死锁

时间:2014-08-08 08:53:02

标签: spring hibernate deadlock c3p0

我在tomcat6上部署了一个webApp,它有一个导入消息功能,它会将大量的消息导入到Oracle 11g数据库中。

在运行导入一段时间之后,偶尔/不可预测地得到deadlock

跟踪

7 août 2014 13:04:38 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@637d7dd6 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
7 août 2014 13:04:38 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@637d7dd6 -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 8
    Active Threads: 8
    Active Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@55e4ef4e (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@45460ed4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@49da1926 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#7)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@14bc659d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@78597c06 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@6667f88e (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@2a5d8dbb (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@441364ad (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
    Pending Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@7ca35537
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@1370b3e5
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@9d7dc72
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@14bfd04d
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@3d0479df
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@27310c3a
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@519c7f0
Pool thread stack traces:
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#7,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:562)


7 août 2014 13:05:13 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@637d7dd6 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
7 août 2014 13:05:13 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@637d7dd6 -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 8
    Active Threads: 8
    Active Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@62ac4df7 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@e8fdc6f (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@4140546 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@70a25e6b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#7)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@33e4fc92 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@4a6064a4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@466c6e60 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@27e87047 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5)
    Pending Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@bdba1dc
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@7be684ff
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@b9b2923
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@292c79d8
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@26f36906
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@114d8aa
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@7bf6e678
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@5c447da5
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@14950af6
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@3124219d
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@7a92974e
Pool thread stack traces:
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
        org.netbeans.lib.profiler.server.ProfilerRuntimeMemory.getAndSendCurrentStackTrace(ProfilerRuntimeMemory.java:221)
        org.netbeans.lib.profiler.server.ProfilerRuntimeObjLiveness.traceObjAlloc(ProfilerRuntimeObjLiveness.java:281)
        com.mchange.v2.c3p0.impl.NewProxyConnection.<init>(NewProxyConnection.java:32)
        com.mchange.v2.c3p0.impl.NewProxyConnection.<init>(NewProxyConnection.java:1376)
        com.mchange.v2.c3p0.impl.NewPooledConnection.getConnection(NewPooledConnection.java:151)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishResourceOnCheckin(C3P0PooledConnectionPool.java:285)
        com.mchange.v2.resourcepool.BasicResourcePool.attemptRefurbishResourceOnCheckin(BasicResourcePool.java:1615)
        com.mchange.v2.resourcepool.BasicResourcePool.access$200(BasicResourcePool.java:32)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1228)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
        org.netbeans.lib.profiler.server.ProfilerRuntimeMemory.getAndSendCurrentStackTrace(ProfilerRuntimeMemory.java:221)
        org.netbeans.lib.profiler.server.ProfilerRuntimeObjLiveness.traceObjAlloc(ProfilerRuntimeObjLiveness.java:281)
        com.mchange.v2.c3p0.impl.NewProxyConnection.<init>(NewProxyConnection.java:32)
        com.mchange.v2.c3p0.impl.NewProxyConnection.<init>(NewProxyConnection.java:1376)
        com.mchange.v2.c3p0.impl.NewPooledConnection.getConnection(NewPooledConnection.java:151)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishResourceOnCheckin(C3P0PooledConnectionPool.java:285)
        com.mchange.v2.resourcepool.BasicResourcePool.attemptRefurbishResourceOnCheckin(BasicResourcePool.java:1615)
        com.mchange.v2.resourcepool.BasicResourcePool.access$200(BasicResourcePool.java:32)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1228)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3,5,main]
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1229)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#7,5,main]
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1229)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
        org.netbeans.lib.profiler.server.ProfilerRuntimeMemory.getAndSendCurrentStackTrace(ProfilerRuntimeMemory.java:221)
        org.netbeans.lib.profiler.server.ProfilerRuntimeObjLiveness.traceObjAlloc(ProfilerRuntimeObjLiveness.java:281)
        java.util.HashMap.addEntry(Unknown Source)
        java.util.HashMap.put(Unknown Source)
        java.util.HashSet.add(Unknown Source)
        com.mchange.v2.c3p0.util.ConnectionEventSupport.addConnectionEventListener(ConnectionEventSupport.java:39)
        com.mchange.v2.c3p0.impl.NewPooledConnection.addConnectionEventListener(NewPooledConnection.java:194)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishResourceOnCheckin(C3P0PooledConnectionPool.java:290)
        com.mchange.v2.resourcepool.BasicResourcePool.attemptRefurbishResourceOnCheckin(BasicResourcePool.java:1615)
        com.mchange.v2.resourcepool.BasicResourcePool.access$200(BasicResourcePool.java:32)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1228)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4,5,main]
        org.netbeans.lib.profiler.server.ProfilerRuntimeMemory.getAndSendCurrentStackTrace(ProfilerRuntimeMemory.java:221)
        org.netbeans.lib.profiler.server.ProfilerRuntimeObjLiveness.traceObjAlloc(ProfilerRuntimeObjLiveness.java:281)
        java.util.HashMap.clone(Unknown Source)
        java.util.HashSet.clone(Unknown Source)
        com.mchange.v2.c3p0.util.ConnectionEventSupport.fireConnectionClosed(ConnectionEventSupport.java:49)
        com.mchange.v2.c3p0.impl.NewPooledConnection.fireConnectionClosed(NewPooledConnection.java:439)
        com.mchange.v2.c3p0.impl.NewPooledConnection.markClosedProxyConnection(NewPooledConnection.java:318)
        com.mchange.v2.c3p0.impl.NewProxyConnection.close(NewProxyConnection.java:1246)
        com.mchange.v1.db.sql.ConnectionUtils.attemptClose(ConnectionUtils.java:41)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishResourceOnCheckin(C3P0PooledConnectionPool.java:292)
        com.mchange.v2.resourcepool.BasicResourcePool.attemptRefurbishResourceOnCheckin(BasicResourcePool.java:1615)
        com.mchange.v2.resourcepool.BasicResourcePool.access$200(BasicResourcePool.java:32)
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1228)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6,5,main]
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1229)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5,5,main]
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask.run(BasicResourcePool.java:1229)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:557)

似乎有大量的RefurbishCheckinResourceTask,根据跟踪,c3p0未能getConnection。我正在使用Springhibernatec3p0

我的c3p0配置

<bean id="pmiDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUrl" value="jdbc:oracle:thin:********" />
    <property name="user" value="****" />
    <property name="password" value="****" />
    <property name="acquireIncrement" value="5" />
    <property name="numHelperThreads" value="6" />
    <property name="minPoolSize" value="10" />
    <property name="initialPoolSize" value="15" />
    <property name="maxPoolSize" value="25" />
</bean>

我的hibernate属性:

<property name="hibernateProperties">
    <value>
        hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
        hibernate.auto_close_session=true
        hibernate.validator.autoregister_listeners=false
        hibernate.validator.apply_to_ddl=false
        hibernate.cache.use_second_level_cache=true
        hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory
        hibernate.cache.use_query_cache=false
        javax.persistence.validation.mode=none
        hibernate.generate_statistics=true
    </value>
</property>

我已经查了很多关于此的论坛,其中一个最相似的案例就是这个。 c3p0 apparent deadlock / creating emergency threadsAPPARENT DEADLOCK 0.9.1.2

请帮忙吗?

1 个答案:

答案 0 :(得分:0)

这不是c3p0问题,实际上是我自己的错。

我使用TaskExecutor来运行多线程内部runnalbe任务。由于此过程从内部实例调用外部类方法,因此它必须处理同步问题,我首先忽略了这一问题。

当内部实例因同步而遇到某些错误时,它会阻止某些c3p0连接返回connection-pool

所以这被证明是一个outer-inner-class instance method来电问题。只需要小心同步问题。

有时错误不会显示在开发计算机上,但是一旦它在具有许多内核的功能更强大的生产计算机上发布,就很容易发生错误。