我在摇摆应用程序中使用带有 c3p0 的休眠来访问数据库。c3p0 配置为c3p0.testConnectionOnCheckout=true
. 因此,如果数据库断开连接(例如超时后),c3p0 会为我建立一个新连接。
它工作正常,但如果 DB 不可访问,c3p0 会冻结 GUI 一段时间,在 colsole 上打印休闲消息
26.06.2013 11:42:46,568 WARN [ThreadPoolAsynchronousRunner run] com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@27d8f985 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
26.06.2013 11:42:46,573 WARN [ThreadPoolAsynchronousRunner run] com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@27d8f985 -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1636d880 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6abfc6e4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@549ad97c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@23c8749
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@53d5cac4
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,6,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-#1,6,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,6,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)
然后大约 7 秒后org.hibernate.exception.GenericJDBCException: Could not open connection
会抛出异常。一直以来,GUI都被阻止了。我真正想做的是显示一些进度条(不确定)和一些合理的消息,比如“连接丢失,试图重新连接”。我怎样才能做到这一点?也许 c3p0 对这样的东西有一些回调?