Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection pooling options with JDBC: DBCP vs C3P0 [closed]

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

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

  • Apache DBCP - http://commons.apache.org/dbcp/
  • C3P0 - http://sourceforge.net/projects/c3p0

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

Are there any relevant alternatives to these two?

like image 673
Dema Avatar asked Feb 06 '09 14:02

Dema


People also ask

Which is the best connection pooling in Java?

There are multiple JDBC frameworks for connection pooling the most popular choices being Tomcat JDBC and HikariCP.

Do we need to close connection in connection pool?

Yes, certainly you need to close the pooled connection as well. It's actually a wrapper around the actual connection. It wil under the covers release the actual connection back to the pool.

What is DBCP connection pool?

The DBCP Component Opening a connection per user can be unfeasible in a publicly-hosted Internet application where the number of simultaneous users can be very large. Accordingly, developers often wish to share a "pool" of open connections between all of the application's current users.

Which has the highest priority for creating connection pool?

Database connection pooling is still achieved through application module pooling. The only exception is when multiple application module pools (and therefore a large number of application module instances) share the same database, making the total available database connections the highest priority.


3 Answers

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.

like image 153
j pimmel Avatar answered Oct 09 '22 20:10

j pimmel


I was having trouble with DBCP when the connections times out so I trialled c3p0. I was going to release this to production but then started performance testing. I found that c3p0 performed terribly. I couldn't configure it to perform well at all. I found it twice as slow as DBCP.

I then tried the Tomcat connection pooling.

This was twice as fast as c3p0 and fixed other issues I was having with DBCP. I spent a lot of time investigating and testing the 3 pools. My advice if you are deploying to Tomcat is to use the new Tomcat JDBC pool.

like image 16
user542651 Avatar answered Oct 09 '22 19:10

user542651


I invite you to try out BoneCP -- 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 :-)

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.

Update #2: (Dec '13) After 4 years at the top, there's now a much faster competitor : https://github.com/brettwooldridge/HikariCP

Update #3: (Sep '14) Please consider BoneCP to be deprecated at this point, recommend switching to HikariCP.

Update #4: (April '15) -- I no longer own the domain jolbox.com

like image 180
wwadge Avatar answered Oct 09 '22 18:10

wwadge