It seems there is a lot of confusion between these two connection pooling libraries. What I want to know is which one is better (if at all)?
Here are some points which I would like to put up... Could someone please verify?
Tomcat DBCP: uses the default tomcat-dbcp.jar which will be present in your tomcat/lib directory. You do not need commons-dbcp.jar or commons-pool.jar libraries in your web-inf/lib. The DB driver should be placed in tomcat/lib.
Tomcat DBCP datasource class is org.apache.tomcat.dbcp.dbcp.BasicDataSource
. Commons DBCP datasource class is org.apache.commons.dbcp.BasicDataSource
.
The only difference between these two can be found in this blog. Do not know if the information is correct or not.
The official Tomcat documentation mentions clearly that most classes have just been re-named and re-packaged.
So the question is: which one to use and which one is better?
This Commons package provides an opportunity to coordinate the efforts required to create and maintain an efficient, feature-rich package under the ASF license. The commons-dbcp2 artifact relies on code in the commons-pool2 artifact to provide the underlying object pool mechanisms.
(boolean) If autoCommit==false then the pool can complete the transaction by calling commit on the connection as it is returned to the pool If rollbackOnReturn==true then this attribute is ignored. Default value is false .
Hazard Summary. 1,2-Dibromo-3-chloropropane (DBCP) was used in the past as a soil fumigant and nematocide on crops; it is no longer used except as an intermediate in chemical synthesis.
Tomcat DBCP is just a renamed version of Apache Commons DBCP, with also a different internal package name prefix.
At build time, Tomcat fetches the Commons DBCP sources (the version depends on the Tomcat version, for instance Tomcat 7.0.27 uses Commons DBCP 1.4), and does package name replacement (org.apache.commons
-> org.apache.tomcat.dbcp
) and builds the result as tomcat-dbcp.jar
.
This is done so that the internal Tomcat JDBC pools never conflict with possible application uses of the Commons DBCP classes. This avoids many potential classloading issues.
Edit: The "dbcp" packages are about datasource management. For the pure pool implementation, Commons DBCP depends on Commons Pool (package org.apache.commons.pool
), but in Tomcat the implementation of the pool is replaced with Tomcat's own JDBC pool (package org.apache.tomcat.jdbc.pool
).
It seems there is a lot of confusion between these two connection pooling libraries. What I want to know is which one is better (if at all)?
TL/DR: these are the same, don't use either of them.
Tomcat-dbcp is the original re-package of apache commons pool included in Tomcat distribution. To avoid class clash package was renamed to org.apache.tomcat.dbcp.dbcp.*
In Tomcat 7 (starting with 7.0.19 in July 2011) an additional connection pool was included in default Tomcat package (as part of tomcat-jdbc.jar) as alternative to stale apache commons implementation, called "The Tomcat JDBC Connection Pool":
https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
This article covers the differences between the two:
http://vigilbose.blogspot.com/2009/03/apache-commons-dbcp-and-tomcat-jdbc.html
Short summary why new Tomcat pool is better:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With