我有一个使用Hibernate的高负载Java应用程序。我曾经使用DBCP作为连接池,但它会出现连接丢失的问题。于是我转而使用了c3p0。但现在它有时会阻塞线程,我不知道原因。就像这样:
"1343694829@qtp-515693101-1941" prio=10 tid=0x00007fa6b0940000 nid=0x4e12 runnable [0x00007fa6f8f1c000]
java.lang.Thread.State: RUNNABLE
at com.mchange.v2.resourcepool.BasicResourcePool.doCheckinManaged(BasicResourcePool.java:1258)
at com.mchange.v2.resourcepool.BasicResourcePool.checkinResource(BasicResourcePool.java:647)
- locked <0x00007fa7286d9728> (a com.mchange.v2.resourcepool.BasicResourcePool)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$ConnectionEventListenerImpl.doCheckinResource(C3P0PooledConnectionPool.java:636)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$ConnectionEventListenerImpl.connectionClosed(C3P0PooledConnectionPool.java:630)
at com.mchange.v2.c3p0.util.ConnectionEventSupport.fireConnectionClosed(ConnectionEventSupport.java:55)
at com.mchange.v2.c3p0.impl.NewPooledConnection.fireConnectionClosed(NewPooledConnection.java:510)
at com.mchange.v2.c3p0.impl.NewPooledConnection.markClosedProxyConnection(NewPooledConnection.java:381)
at com.mchange.v2.c3p0.impl.NewProxyConnection.close(NewProxyConnection.java:1246)
- locked <0x00007fa794ccf020> (a com.mchange.v2.c3p0.impl.NewProxyConnection)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.closeConnection(LocalDataSourceConnectionProvider.java:96)
at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:408)
at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:347)
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:325)
at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession(SessionFactoryUtils.java:791)
at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSessionOrRegisterDeferredClose(SessionFactoryUtils.java:777)
at org.springframework.orm.hibernate3.SessionFactoryUtils.releaseSession(SessionFactoryUtils.java:755)
我的堆栈跟踪转储显示,这个线程使用锁<0x00007fa7286d9728>,阻塞了所有其他线程,因此服务器在一段时间内完全被阻塞。我不确定这个线程运行了多长时间,如果一个线程长时间阻塞了所有其他线程,或者只是这个线程消耗的时间极长,但结果是,我的系统完全被阻塞并且极慢。我搜索了很多,但不知道如何解决这个问题。我需要池来关闭连接并尽快完成线程。我应该使用其他连接池吗?对于我来说,这个池库绝对必须是100%安全的,没有死锁、活锁、饥饿,即使它比其他库稍微慢一点。
感谢任何帮助