C3p0 APPARENT DEADLOCK异常

时间:2013-08-07 10:01:35

标签: mysql hibernate c3p0 database-deadlocks

我在Tomcat日志中不断收到此异常:

com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@76b28200 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@76b28200 -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 3
    Active Threads: 3
    Active Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1201fd18 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@408f3be4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7ba516d8 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
    Pending Tasks: 
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@137efe53
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@766b0524
Pool thread stack traces:
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
        java.lang.Thread.sleep(Native Method)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
        java.lang.Thread.sleep(Native Method)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
        java.lang.Thread.sleep(Native Method)
        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

我正在使用Hibernate 3.6.2和C3P0 0.9.1.2与MySQL。经过几个小时的Google搜索,这个APPARENT DEADLOCK异常似乎通常与准备好的语句缓存相关联。这是我在hibernate.cfg.xml中的C3P0配置:

<propertyname="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">60</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.timeout">180</property>              
<property name="hibernate.c3p0.max_statements">0</property>

我没有做任何声明缓存。任何有关错误的提示都将不胜感激。

3 个答案:

答案 0 :(得分:9)

交易的任务是连接获取任务。也就是说,c3p0正试图从您的数据库中获取新的连接,并且这些连接获取尝试需要很长时间。

我要做的第一件事就是升级到0.9.2.1,在收购尝试有时会失败的情况下,它有一个很好的方法来执行一轮连接采集。

如果这不能解决您的问题,那么您需要弄清楚为什么c3p0尝试获取连接会长时间挂起:既没有成功也没有因为异常而失败。

答案 1 :(得分:1)

在我的特殊情况下,问题与我部署应用程序的服务器的配置有关。

只有在我的应用程序的堆栈跟踪打印出来后才挂起,因为oracle驱动程序正在等待生成一个安全的随机数:

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
  java.io.FileInputStream.readBytes(Native Method)
  java.io.FileInputStream.read(FileInputStream.java:255)
  sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedBytes(SeedGenerator.java:539)
  sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:144)
  sun.security.provider.SecureRandom$SeederHolder.(SecureRandom.java:203)
  sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:221)
  java.security.SecureRandom.nextBytes(SecureRandom.java:468)
  oracle.security.o5logon.O5Logon.a(Unknown Source)
  oracle.security.o5logon.O5Logon.(Unknown Source)
  oracle.jdbc.driver.T4CTTIoauthenticate.(T4CTTIoauthenticate.java:582)
  oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
  oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:553)
  oracle.jdbc.driver.T4CConnection.(T4CConnection.java:254)
  oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
  oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
  com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
  com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
  com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
  com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
  com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
  com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
  com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

然后我必须学习并理解一些关于熵噪声的知识,并且在我的Unix朋友的帮助下,可以意识到其中一个服务器没有安装产生“噪音”的软件包。

如下文所述,我运行了下一个命令: cat /proc/sys/kernel/random/entropy_avail 23 cat /proc/sys/kernel/random/poolsize 4096

因此,可用于生成安全随机数的熵太少。

安装包后 cat /proc/sys/kernel/random/entropy_avail 4096 之后我没有明显的死锁,我的应用程序可以连接到数据库。

http://www.usn-it.de/index.php/2009/02/20/oracle-11g-jdbc-driver-hangs-blocked-by-devrandom-entropy-pool-empty/

答案 2 :(得分:0)

之前有类似的错误。

它也可能是由数据库服务器阻止您的IP引起的。确保数据库服务器/云提供程序不阻止服务器的IP。

就我而言,尝试使用多线程将数据插入云中的数据库,它只能在本地工作,但不能在服务器上工作(在不同的网络上)。