JDBC connection pooling

It is tricky to know how best to configure connection pooling. The main libraries in use seem to be Apache DBCP and C3P0. Benchmarks show DBCP to be a lot faster in single threaded case, and C3PO is more scalable (for example, see this incomplete article).

As there does not seem to be a clear winner, I tend to look for alternatives. BoneCP seems to be a good candidate. They have a large set of benchmarks, which seems to be sensible (and comparable to the tests in the link above).

Now, in a specific project we were having problems with our application being horribly slow (and likely deadlocking) on the test server. We were using DBCP as connection pool. Switching the configuration over to BoneCP has made the system much more responsive. So it seems to be a winner.

The Hibernate/Spring configuration we use looks like this:

  <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
     <property name="driverClass" value="org.postgresql.Driver" />
     <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/dbname" />
     <property name="username" value="user"/>
     <property name="password" value="pw"/>
     <property name="idleConnectionTestPeriod" value="60"/>
     <property name="idleMaxAge" value="240"/>
     <property name="maxConnectionsPerPartition" value="30"/>
     <property name="minConnectionsPerPartition" value="10"/>
     <property name="partitionCount" value="3"/>
     <property name="acquireIncrement" value="5"/>
     <property name="statementsCacheSize" value="100"/>
     <property name="releaseHelperThreads" value="3"/>


  1. Just would like to point out that in the newer version (v0.7.1.RELEASE) some config options have been made more clear.

    idleConnectionTestPeriod has become idleConnectionTestPeriodInMinutes for example (same thing for idleMaxAge).

    The old properties will still work though.


  2. Leonardo says:

    I didn’t find anything about BoneCP configurations about defaultTimeout, and it made me a little bit worried.
    Entretanto, I tested it in my development AND production environments, and the performance gain was quite impressive!
    A very, very nice tip, thank you!
    Regards from Brazil!

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen