问题描述
这两个连接池库之间似乎存在很多混淆.我想知道哪个更好(如果有的话)?
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:使用默认的 tomcat-dbcp.jar,它将出现在您的 tomcat/lib 目录中.您不需要 web-inf/lib 中的 commons-dbcp.jar 或 commons-pool.jar 库.DB驱动应该放在tomcat/lib中.
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 数据源类是 org.apache.tomcat.dbcp.dbcp.BasicDataSource
.Commons DBCP 数据源类是 org.apache.commons.dbcp.BasicDataSource
.
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.
Tomcat 官方文档 清楚地提到大多数类刚刚被重新命名和重新打包.
The official Tomcat documentation mentions clearly that most classes have just been re-named and re-packaged.
所以问题是:使用哪个,哪个更好?
推荐答案
Tomcat DBCP 只是 Apache Commons DBCP 的重命名版本,也有不同的内部包名称前缀.
Tomcat DBCP is just a renamed version of Apache Commons DBCP, with also a different internal package name prefix.
在构建时,Tomcat 获取 Commons DBCP 源(版本取决于 Tomcat 版本,例如 Tomcat 7.0.27 使用 Commons DBCP 1.4),并进行包名替换(org.apache.commons
code> -> org.apache.tomcat.dbcp
) 并将结果构建为 tomcat-dbcp.jar
.
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
.
这样做是为了使内部 Tomcat JDBC 池永远不会与 Commons DBCP 类的可能应用程序使用发生冲突.这避免了许多潜在的类加载问题.
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.
dbcp"包是关于数据源管理的.对于纯池实现,Commons DBCP 依赖于 Commons Pool(包 org.apache.commons.pool
),但在 Tomcat 中,池的实现被 Tomcat 自己的 JDBC 池(包org.apache.tomcat.jdbc.pool
).
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
).
这篇关于tomcat-dbcp 与 commons-dbcp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!