I want to add database connection pooling to an existing application. I found two libraries based on tomcat tomcat-dbcp
and tomcat-jdbc
. I am just getting into trouble which one should I go for?
CodePudding user response:
In summary
Notes from a member of the Tomcat commit team (see here):
Tomcat JDBC is Tomcat’s "home grown" database connection pooling and does not use poolPreparedStatements. Tomcat DBCP is Tomcat’s package renamed fork of Apache Commons DBCP 2. Tomcat DBCP is used by default.
The Default DBCP 2 Tomcat Pool
This is the newer of the two pools included in Tomcat and it is the one used by default. It is based on the Commons DBCP 2 pool, as described here.
You can see more details by visiting the official DBCP site.
Tomcat's Home-Grown JDBC Pool
The main documentation page for this is here.
You may see this referred to as "new" in some places in the Tomcat documentation - for example here:
So why do we need a new connection pool?
It was new at one point in time. It was superseded by the DBCP2 pool.
Which One to Use?
That is somewhat a matter of opinion and may also depend on your specific circumstances. You can start with Tomcat's default DBCP 2 pool, if you cannot decide.
Just to add: You can use either of the above pools with Tomcat, or you can use other pools such as HikariCP, c3p0 and so on. You don't have to choose only between the two Tomcat-provided pools.