表观死锁使用JPA2.0和Hibernate为未分配的待处理任务创建紧急线程

时间:2013-11-27 14:22:16

标签: java hibernate tomcat jpa

1)我们正在使用JPA2.0和Hibernate 4.2,我们最初使用Hibernate默认连接池实现了数据库连接。我们认为这是outofmemory错误的问题,我们也在日志中看到了Hibernate内置连接池(不用于生产用途!)

java.lang.OutOfMemoryError: Java heap space

2)所以实现了C3P0连接池,请参见下面的persistence.xml文件,并在tomcat服务中进行更改以设置JAVA_OPTS。

From - JAVA_OPTS="-Xms256m -Xmx2048m -XX:PermSize=1024m -XX:MaxPermSize=1024m"
To – JAVA_OPTS="-Xmx2G -Xms1G -XX:NewSize=500m -XX:MaxPermSize=500m -XX:CMSInitiatingOccupancyFraction=40"

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="pub-test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<property name="javax.persistence.jdbc.url"
value="jdbc:informix-sqli://fddb.fd.gtwy.dcn:7101/fd_test:INFORMIXSERVER=fd_ecf" />
<property name="javax.persistence.jdbc.user" value="dcapps" />
<property name="javax.persistence.jdbc.password" value="*****" />
<property name="javax.persistence.jdbc.driver" value="com.informix.jdbc.IfxDriver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect" />
<property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="1000" />
<property name="hibernate.c3p0.min_size" value="30" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.acquireRetryAttempts" value="60"/>
<property name="hibernate.c3p0.idle_test_period" value="30" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
<property name="hibernate.auto_close_session" value="false"/>
<property name="hibernate.c3p0.breakAfterAcquireFailure" value="false"/>
<property name="hibernate.c3p0.numHelperThreads" value="3"/>
<property name="hibernate.c3p0.testConnectionOnCheckin" value="true"/>

3)我们遇到了这个问题(见下文)所以我将log4j级别更改为WARN以忽略Info消息。

2013-11-21 17:09:46 INFO  SQLWarnings:43 - Database has transactions
java.sql.SQLWarning: Database has transactions
    at com.informix.util.IfxWarnMsg.getSQLWarning(IfxWarnMsg.java:125)
    at com.informix.util.IfxWarnMsg.getSQLWarning(IfxWarnMsg.java:149)
    at com.informix.jdbc.IfxSqliConnect.a(IfxSqliConnect.java:2272)
    at com.informix.jdbc.IfxSqliConnect.t(IfxSqliConnect.java:4542)
    at com.informix.jdbc.IfxSqliConnect.b(IfxSqliConnect.java:3100)
    at com.informix.jdbc.IfxSqliConnect.a(IfxSqliConnect.java:2973)
    at com.informix.jdbc.IfxSqli.c(IfxSqli.java:2843)
    at com.informix.jdbc.IfxSqli.executeOpenDatabase(IfxSqli.java:2034)
    at com.informix.jdbc.IfxSqliConnect.<init>(IfxSqliConnect.java:1622)
    at sun.reflect.GeneratedConstructorAccessor42.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.informix.jdbc.IfxDriver.connect(IfxDriver.java:254)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-11-21 17:09:46 INFO  SQLWarnings:43 - Database selected
java.sql.SQLWarning: Database selected
    at com.informix.util.IfxWarnMsg.getSQLWarning(IfxWarnMsg.java:125)
    at com.informix.util.IfxWarnMsg.getSQLWarning(IfxWarnMsg.java:149)
    at com.informix.jdbc.IfxSqliConnect.a(IfxSqliConnect.java:2272)
    at com.informix.jdbc.IfxSqliConnect.t(IfxSqliConnect.java:4548)
    at com.informix.jdbc.IfxSqliConnect.b(IfxSqliConnect.java:3100)
    at com.informix.jdbc.IfxSqliConnect.a(IfxSqliConnect.java:2973)
    at com.informix.jdbc.IfxSqli.c(IfxSqli.java:2843)
    at com.informix.jdbc.IfxSqli.executeOpenDatabase(IfxSqli.java:2034)
    at com.informix.jdbc.IfxSqliConnect.<init>(IfxSqliConnect.java:1622)
    at sun.reflect.GeneratedConstructorAccessor42.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.informix.jdbc.IfxDriver.connect(IfxDriver.java:254)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-11-21 17:09:46 INFO  TransactionFactoryInitiator:73 - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory

4)我们遇到了这个问题(见下文)并且它也抱怨“打开的文件太多”,所以为了解决这个问题,我们已经将ulimit更改为4096,这就解决了这个问题。 Tomcat正在尝试保存有关应用程序的信息,以便在启动时使用,并且该信息存储在SESSIONS.ser中 5)现在我们在尝试测试报告(负载测试)之后遇到了这个问题(见下文),即使它是一个警告消息它仍然会降低应用程序性能,但在这些异常之后tomcat太慢了。

2013-11-25 16:39:12 WARN  ThreadPoolAsynchronousRunner:608 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@2bb8cbc9 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
2013-11-25 16:39:12 WARN  ThreadPoolAsynchronousRunner:624 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@2bb8cbc9 -- APPARENT DEADLOCK!!! Complete Status:
        Managed Threads: 3
        Active Threads: 3
        Active Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@714b0f8b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@76e9a8c8 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@66481f75 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
        Pending Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@9096ec9
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4a4852c1
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@52312300
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@17f0ff28
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4effa75f
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7245767d
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2e664327
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3bc2cd3d
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@72307e71
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4dbd6748
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4dc7cfd7
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@791e5425
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@36268742
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1b7a19d4
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6d35bb63
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@62a19898
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5f2955be
Pool thread stack traces:

6)要解决此问题,我们已使用Google帮助并向persistence.xml添加了属性,但我仍然看到相同的异常

We have Set this to zero
<property name="hibernate.c3p0.max_statements" value="0" />

Added these properties
<property name="hibernate.auto_close_session" value="false"/>
<property name="hibernate.c3p0.acquireRetryAttempts" value="60"/>

0 个答案:

没有答案