views:

11826

answers:

10

What is the best connection pooling library available for Java/JDBC?

I'm considering the 2 main candidates (free / open-source):

I've read a lot about them in blogs and other forums but could not reach a decision.

Is there any relevant alternatives to this two?

+2  A: 

Another alternative, Proxool, is mentioned in this article.

You might be able to find out why Hibernate bundles c3p0 for its default connection pool implementation?

toolkit
+22  A: 

DBCP is out of date and not production grade. Some time back we conducted an in-house analysis of the two, creating a test fixture which generated load and concurrency against the two to assess their suitability under real life conditions.

DBCP consistently generated exceptions into our test application and struggled to reach levels of performance which C3P0 was more than capable of handling without any exceptions.

C3P0 also robustly handled DB disconnects and transparent reconnects on resume whereas DBCP never recovered connections if the link was taken out from beneath it. Worse still DBCP was returning Connection objects to the application for which the underlying transport had broken.

Since then we have used C3P0 in 4 major heavy-load consumer web apps and have never looked back.

UPDATE: It turns out that after many years of sitting on a shelf, the Apache Commons folk have taken DBCP out of dormancy and it is now, once again, an actively developed project. Thus my original post may be out of date.

That being said, I haven't yet experienced this new upgraded library's performance, nor heard of it being de-facto in any recent app framework, yet.

j pimmel
Thanks! How about the suggested Proxool alternative? The current version of Hibernate comes with both c3p0 and Proxool.
Dema
We haven't tried Proxool but I'll be sure to check it out now :)
j pimmel
If you need XA connections, go for Proxool, else go for C3P0 which is just a tad better.
BalusC
c3p0 has some drawbacks. it sometimes fails to handle connection peaks.
Janning
+5  A: 

For the auto-reconnect issue with DBCP, has any tried using the following 2 configuraiton parameters?

validationQuery="Some Query"

testOnBorrow=true

Brandon Teo
+2  A: 

Unfortunately they are all out of date. DBCP has been updated a bit recently, the other two are 2-3 years old, with many outstanding bugs.

That is true - the last release of C3PO (a 0.9 pre-release) is from May 2007. The latest release of Proxool (a 0.9 pre-release) is from August 2008. The last release of DBCP is also from Apr 2007, but at least its a stable 1.2 release. Is there anything actually maintained out there?
Guss
To be fair these are not big projects so you should expect fewer and fewer updates in C3P0/DBCP and time goes by.
+9  A: 

Hi,

I invite you to try out BoneCP (http://jolbox.com) -- it's free, open source, and faster than the available alternatives (see benchmark section).

Disclaimer: I'm the author so you could say I'm biased :-)

Wallace

UPDATE: As of March 2010, still around 35% faster than the new rewritten Apache DBCP ("tomcat jdbc") pool. See dynamic benchmark link in benchmark section.

Would really love get a troubleshoot using BoneCP as a Tomcat Datasource. The main problem I had with this was that it required BoneCP Classes in tomcat's lib dir, as well as the log4j and google classes. Doing this made the connection pools work - (it hadn't worked while in WAR) - however it conflicted with the log4j setting of Tomcat and prevented any log output at all from the application, which was a dealbreaker...
j pimmel
This sounds like a log4j issue more than anything else. Drop me a line on forum.jolbox.com and I'll help you track it down ASAP.
+1  A: 

Here are some articles that show that DBCP has significantly higher performance than C3P0 or Proxool. Also in my own experience c3p0 does have some nice features, like prepared statement pooling and is more configurable than DBCP, but DBCP is plainly faster in any environment I have used it in.

Difference between dbcp and c3p0? Absolutely nothing! (A Sakai developers blog) http://blogs.nyu.edu/blogs/nrm216/sakaidelic/2007/12/difference_between_dbcp_and_c3.html

See also the like to the JavaTech article "Connection Pool Showdown" in the comments on the blog post.

Fred Garvin
faster in single threaded environments, maybe, buggy and un-stable and just plain broken anywhere else.
fuzzy lollipop
A: 

Just got done wasting a day and a half with DBCP. Even though I'm using the latest DBCP release, I ran into exactly the same problems as j pimmel (above) did. I would not recommend DBCP at all, especially it's knack of throwing connections out of the pool when the DB goes away, its inability to reconnect when the DB comes back and its inability to dynamically add connection objects back into the pool (it hangs forever on a post JDBCconnect I/O socket read)

I'm switching over to C3P0 now. I've used that in previous projects and it worked and performed like a charm.
Larry H
+3  A: 

Since Tomcat 7.0, there's a new builtin pool available. All you need to do is to update the JNDI datasource factory to point to org.apache.tomcat.jdbc.pool.DataSourceFactory.

The Tomcat 7.0 JDBC connection pool documentation itself is also very clear about the disadvantages of DBCP. Here's an extract of relevance:

  1. commons-dbcp is single threaded, in order to be thread safe commons-dbcp locks the entire pool, even during query validation.
  2. commons-dbcp is slow - as the number of logical CPUs grow, the performance suffers, the above point shows that there is not support for high concurrency Even with the enormous optimizations of the synchronized statement in Java 6, commons-dbcp still suffers in speed and concurrency.
  3. commons-dbcp is complex, over 60 classes. tomcat-jdbc-pool, core is 8 classes, hence modifications for future requirement will require much less changes. This is all you need to run the connection pool itself, the rest is gravy.
  4. commons-dbcp uses static interfaces. This means you can't compile it with JDK 1.6, or if you run on JDK 1.6/1.7 you will get NoSuchMethodException for all the methods not implemented, even if the driver supports it.
  5. The commons-dbcp has become fairly stagnant. Sparse updates, releases, and new feature support.
  6. It's not worth rewriting over 60 classes, when something as a connection pool can be accomplished with as a much simpler implementation.
  7. Tomcat jdbc pool implements a fairness option not available in commons-dbcp and still performs faster than commons-dbcp
  8. Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself
  9. Tomcat jdbc pool is a Tomcat module, it depends on Tomcat JULI, a simplified logging framework used in Tomcat.
  10. Retrieve the underlying connection using the javax.sql.PooledConnection interface.
  11. Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned, the pool will awake the correct thread waiting. Most pools will simply starve.

This pool can also be used on Tomcat 6.0, you just have to download and drop the latest release of the tomcat-jdbc.jar in Tomcat/lib and update the datasource factory accordingly.

The JDBC-pool, the (latest!) DBCP and C3P0 have been benchmarked by Tomcatexpert.com last March. Unfortunately they couldn't configure C3P0 to get it to perform correctly for some reason, so its benches are a bit off.

BalusC
A: 

What about DBPool? Have anybody tried it? It seems to have the same features and performance as c3p0.

JCRamirez
A: 

A good alternative which is easy to use is DBPool.

"A Java-based database connection pooling utility, supporting time-based expiry, statement caching, connection validation, and easy configuration using a pool manager."

http://www.snaq.net/java/DBPool/

Soundlink