我有大量使用hirbernate的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)

'
我的stacktrace转储显示此线程使用锁锁定了我的所有其他线程,因此一段时间后服务器被完全阻止。我不确定该线程运行了多长时间,或者一个线程长时间阻塞了所有其他线程,或者该线程消耗的时间太长了,但是结果是,我的系统被完全阻塞并且极慢了。我用谷歌搜索了很多,但是我不知道如何解决这个问题。我需要游泳池以关闭连接并尽快完成踩踏。我应该使用其他连接池吗?对我来说,绝对有必要将此池库保存为100%,没有死锁,生命锁,饥饿,甚至比其他库慢一点。

谢谢你的帮助

最佳答案

您可能希望看看BoneCP-http://jolbox.com

与C3P0/DBCP相比,性能要好得多,并且到目前为止,还没有任何死锁的报告。

10-07 16:22
查看更多