Java – C3PO helper thread deadlock
I use C3PO pool with my GUI application I have the following configuration
overrides.put("maxStatementsPerConnection",30); overrides.put("maxPoolSize",70); overrides.put("checkoutTimeout",50000);
Occasionally, I encounter a timeout when trying to connect
java.sql.sqlException: An attempt by a client to checkout a Connection has timed out. at com.mchange.v2.sql.sqlUtils.tosqlException(sqlUtils.java:106) at com.mchange.v2.sql.sqlUtils.tosqlException(sqlUtils.java:65) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at com.jthink.jaikoz.db.Db.createConnection(Db.java:402)
Even if I'm sure I have no other contact to open In fact, I have tried to enable some additional options (debug unreturned connection stacktraces, unreturned connection timeout) to identify the problem of unclosed connections and found no problem This problem rarely occurs and only occurs after running for a period of time I'm using an embedded Derby database
Fortunately, when it failed, I was running it and enabled youkit profiler. I could monitor and analyze it and found that three C3PO threads were waiting for each other. That's why I think there is actually a deadlock here
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread#0 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread#1 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread#2
Is this similar to the setting of numhelperthreads?
I took such a screendump
I found a problem with C3PO. Can I recover from it?
Solution
The three threads you see are really helper threads These can slow down JDBC operations asynchronously, such as closing unused connections Last line of stack trace
com.jthink.jaikoz.db.Db.createConnection(Db.java:402)
It seems that c3p0 is trying to open a new connection, but the database refuses to create one I assume that the 'jaikoz' database refuses to connect, and the c3p0 connection pool is not a problem
Simon