2012-07-26 93 views
2

我有一个webservice - java/hibernate/mysql/innoDB。 我不断收到apperante死锁异常。 我环顾四周净,并试图什么建议,但仍然有问题...java + hibernate webservice - 外挂死锁

我使用下面我休眠CFG: hibernate.cfg:

<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> 
    <property name="connection.autoReconnect">true</property> 
    <property name="connection.autoReconnectForPools">true</property> 
    <property name="connection.is-connection-validation-required">true</property> 
    <property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> 
    <property name="hibernate.show_sql">false</property> 
    <property name="hibernate.current_session_context_class">thread</property> 
    <property name="hibernate.format_sql">true</property> 
    <property name="hibernate.use_sql_comments">true</property> 
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property> 

    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
    <property name="hibernate.c3p0.min_size">5</property> 
    <property name="hibernate.c3p0.max_size">50</property> 
    <property name="hibernate.c3p0.timeout">1800</property> 
    <property name="hibernate.c3p0.max_statements">50</property> 
    <property name="hibernate.c3p0.acquire_increment">1</property> 
    <!-- this property forces the revalidation of a connection after the given amount of time (in secs) --> 
    <!-- it must be set to LESS than the wait_timout setting for the mysql server (this setting defaults to 28800 secs (8 hours)) --> 
    <property name="hibernate.c3p0.idle_test_period">2100</property> 

c3p0.properties:

c3p0.properties

c3p0.testConnectionOnCheckout =真

c3p0.preferredTest查询= SELECT 1;

我得到以下异常:

[WARN] com[email protected]1e5161e1 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 
[WARN] com[email protected]1e5161e1 -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 3 
    Active Threads: 3 
    Active Tasks: 
     com.mcha[email protected]60dd0912 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) 
     com.mcha[email protected]4f7eae6c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) 
     com.mcha[email protected]5ed5d3a (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) 
    Pending Tasks: 
     com.mcha[email protected]22838de0 
     com.mcha[email protected]6ad77ed3 
Pool thread stack traces: 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main] 
     java.net.SocketInputStream.socketRead0(Native Method) 
     java.net.SocketInputStream.read(SocketInputStream.java:146) 
     com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114) 
     com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161) 
     com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189) 
     com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2537) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2990) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2979) 
     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3520) 
     com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) 
     com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) 
     com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1521) 
     com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35) 
     com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:73) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:374) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310) 
     com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main] 
     java.net.SocketInputStream.socketRead0(Native Method) 
     java.net.SocketInputStream.read(SocketInputStream.java:146) 
     com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114) 
     com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161) 
     com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189) 
     com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2537) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2990) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2979) 
     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3520) 
     com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) 
     com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) 
     com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1521) 
     com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35) 
     com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:73) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:374) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310) 
     com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main] 
     java.net.SocketInputStream.socketRead0(Native Method) 
     java.net.SocketInputStream.read(SocketInputStream.java:146) 
     com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114) 
     com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161) 
     com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189) 
     com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2537) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2990) 
     com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2979) 
     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3520) 
     com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) 
     com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) 
     com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) 
     com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1521) 
     com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35) 
     com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:73) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:374) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310) 
     com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 


[WARN] Task com.mcha[email protected]60dd0912 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[WARN] Task com.mcha[email protected]4f7eae6c (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[WARN] Task com.mcha[email protected]5ed5d3a (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[WARN] com[email protected]1e5161e1 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 
[WARN] com[email protected]1e5161e1 -- APPARENT DEADLOCK!!! Complete Status: 
    Managed Threads: 3 
    Active Threads: 3 
    Active Tasks: 
     com[email protected]555214b9 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) 
     com[email protected]7fcea971 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) 
     com[email protected]58d67b44 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) 
    Pending Tasks: 
     com[email protected]6936daec 
     [email protected]eb 
     [email protected]b2 
     [email protected]be 
     [email protected]7c 
Pool thread stack traces: 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main] 
     com.mysql.jdbc.StatementImpl.close(StatementImpl.java:550) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.cleanupUncachedStatements(NewPooledConnection.java:651) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:539) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) 
     com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main] 
     com.mysql.jdbc.StatementImpl.close(StatementImpl.java:550) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.cleanupUncachedStatements(NewPooledConnection.java:651) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:539) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) 
     com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 
    Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main] 
     com.mysql.jdbc.StatementImpl.close(StatementImpl.java:550) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.cleanupUncachedStatements(NewPooledConnection.java:651) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:539) 
     com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234) 
     com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) 
     com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) 
     com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 


[WARN] Task com[email protected]555214b9 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[WARN] Task com[email protected]7fcea971 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
[WARN] Task com[email protected]58d67b44 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(). 
+1

死锁是一个SQL编程问题,而不是连接池相关的问题。死锁是当进程1正在锁定表A并且正在等待锁定表B并且进程2正在锁定表B并且正在等待A. – 2012-07-26 12:28:38

回答

1

你到底想干什么?对我来说,有一些东西可以让你的数据库连接保持打开状态。因此,c3p0正试图获得更多连接来处理额外的请求。

+0

这很奇怪你在说什么,因为我在代码中需要使用session.commit() 。所以连接应该关闭。我对么? – user1365799 2012-07-26 12:29:37

+0

session.commit()不会关闭您的数据库连接。您是否正在使用您从未提交或回滚的交易? – 2012-07-26 12:31:22

+0

我所有的事务都在提交/回滚。每个ServerAPI函数获取事务并始终提交/回滚。如果我需要提供更多有助于解决的信息 - 将很乐意提供 – user1365799 2012-07-26 12:36:23