apache-commons-dbcp deadlock java spring tomcat

Deadlock issue in DBCP deployed on Tomcat

I’m using DBCP data source (with default configuration) in Spring configuration to manage my connections to the database, and I’m running into a deadlock condition when the number of clients increase.

I found that there is a deadlock issue in DBCP 1.2.1 which I was using, which was supposed to be resolved in 1.4. So I upgraded to 1.4, but the issue still persists.

In the thread dump, there are many threads blocked with the following stack trace on top:

   java.lang.Thread.State: WAITING on [email protected]
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(
at org.apache.commons.dbcp.PoolingDataSource.getConnection(
at org.apache.commons.dbcp.BasicDataSource.getConnection(
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(

Any suggestions are welcome!

I switched to c3p0, few years back. You can try that. I believe you didn’t have to change much, it’s just a game of configuration.

Somewhat related thread, Connection pooling options with JDBC: DBCP vs C3P0. Well, actually I made it related.

[edited, 19/10/12]

Tomcat 7 has a decent connection pool, The Tomcat JDBC Connection Pool.