简体   繁体   English

为什么使用tomcat进行数据库连接池有两种选择(tomcat-dbcp和tomcat-jdbc)?

[英]Why there are two options for database connection pooling with tomcat (tomcat-dbcp and tomcat-jdbc)?

I want to add database connection pooling to an existing application.我想向现有应用程序添加数据库连接池。 I found two libraries based on tomcat tomcat-dbcp and tomcat-jdbc .我找到了两个基于 tomcat tomcat-dbcptomcat-jdbc I am just getting into trouble which one should I go for?我只是遇到了麻烦我应该去哪一个?

In summary总之

Notes from a member of the Tomcat commit team (see here ):来自 Tomcat 提交团队成员的注释(请参阅此处):

Tomcat JDBC is Tomcat's "home grown" database connection pooling and does not use poolPreparedStatements. Tomcat JDBC 是 Tomcat 的“本土”数据库连接池,不使用 poolPreparedStatements。 Tomcat DBCP is Tomcat's package renamed fork of Apache Commons DBCP 2. Tomcat DBCP is used by default. Tomcat DBCP 是 Apache Commons DBCP 2 的 Tomcat 包重命名分支。默认使用 Tomcat DBCP。

The Default DBCP 2 Tomcat Pool默认的 DBCP 2 Tomcat 池

This is the newer of the two pools included in Tomcat and it is the one used by default.这是 Tomcat 中包含的两个池中较新的一个,也是默认使用的一个。 It is based on the Commons DBCP 2 pool, as described here .它是基于通用DBCP 2池,描述在这里

You can see more details by visiting the official DBCP site .您可以通过访问官方 DBCP 站点查看更多详细信息。

Tomcat's Home-Grown JDBC Pool Tomcat 的自有 JDBC 池

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 :您可能会在 Tomcat 文档的某些地方看到这被称为“新”——例如这里

So why do we need a new connection pool?那么为什么我们需要一个新的连接池呢?

It was new at one point in time.它在某个时间点新的。 It was superseded by the DBCP2 pool.它被 DBCP2 池取代。

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.如果您不能决定,您可以从 Tomcat 的默认 DBCP 2 池开始。

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.补充一点:您可以将上述任何一个池与 Tomcat 一起使用,也可以使用其他池,例如HikariCPc3p0等。 You don't have to choose only between the two Tomcat-provided pools.您不必在 Tomcat 提供的两个池之间进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM