Features comparison of Vibur DBCP, Commons DBCP 1.4, and C3P0

This is an updated version of a post that first appeared on coderanch in December 2013.

Guarantee that no thread will be starved out from accessing the pool resources:

  • Vibur DBCP provides such support via a standard Java Semaphore.
  • Apache Commons DBCP provides such support via custom implementation in Apache Commons Pool.
  • C3P0 - no support.

Detection and logging of long running SQL queries and long lasting getConnection() method calls:

  • Vibur DBCP provides support for both of these. A slow SQL queries log sample can be seen here and a slow getConnection() calls log sample is shown here.
  • Apache Commons DBCP and C3P0 - no support.

Hibernate 3.x and 4.x integration support:

  • Vibur DBCP comes with Hibernate3 and Hibernate4 integrations.
  • Apache Commons DBCP does not have built-in support for Hibernate; however, a class providing integration for Hibernate 3.x is publicly available.
  • C3P0 has integration for Hibernate 3.x and 4.x as part of the Hibernate distributions.

Built using standard Java concurrency utilities:

  • Vibur DBCP does not use any synchronized blocks/methods during normal pool operation. At a low level, the object pooling is built on top of a standard ConcurrentLinkedQueue, which is guarded by a standard Semaphore, and a ConcurrentLinkedHashMap is utilized for JDBC Statement caching purposes.
  • Both Apache Commons DBCP and C3P0 make heavy use of synchronized blocks/methods as part of their pool operations.

Source code size:

  • Having an overall design that is as simple as possible as well as concise and easy to maintain source code was one of the main objectives of Vibur DBCP. Currently it has approximately 30 source files and about 3.3K SLOC total.
  • Apache Commons DBCP includes over 75 source files and C3P0 has over 90 source files. Both have a considerably larger SLOC total than Vibur DBCP.

Built on top of a separate and dedicated object pool project:

  • Vibur DBCP is built on top of a Vibur Object Pool.
  • Apache Commons DBCP is built on top of an Apache Commons Pool.
  • For C3P0 the object pooling implementation is part of the C3P0 source code.

JDBC Connection validation:

  • Vibur DBCP validates the JDBC connections on take if they have been idle for longer than a configured time, and implements this via calling the standard Connection.isValid() method or via executing a configured custom query. Can be configured to validate the connections on every take.
  • Both Apache Commons DBCP and C3P0 can validate the JDBC connections on take, restore, or while idle via executing a configured custom query.

Eviction of idle JDBC Connections:

  • Vibur DBCP supports this via configuring reducerTimeIntervalInSeconds and reducerSamples.
  • Apache Commons DBCP supports this via configuring timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, and minEvictableIdleTimeMillis.
  • C3P0 supports this via configuring maxConnectionAge, maxIdleTime, and maxIdleTimeExcessConnections.

Caching support for JDBC Statements (Prepared and Callable):

  • Implemented in one way or another by all pools.

Access to the raw (underlying) JDBC Connection:

  • Implemented in one way or another by all pools.

Providing records (including stack traces) for all currently taken (unclosed) JDBC connections:

  • Implemented in one way or another by all pools.