DBCP(Apache Commons 数据库连接池)是否仍然相关? [英] Is DBCP (Apache Commons Database Connection Pooling) still relevant?

查看:28
本文介绍了DBCP(Apache Commons 数据库连接池)是否仍然相关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JDBC 3.0 规范讨论了连接(和准备好的语句)池.

The JDBC 3.0 spec talks about Connection (and Prepared Statement) pooling.

我们有几个独立的 Java 程序(即我们没有使用应用服务器),它们一直在使用 DBCP 来提供连接池.我们应该继续使用 DBCP,还是可以利用 JDBC 提供的池来摆脱 DBCP?

We have several standalone Java programs (i.e. we are not using an application server) that have been using DBCP to provide connection pooling. Should we continue to use DBCP, or can we take advantage of the JDBC-provided pooling and get rid of DBCP?

我们正在使用 MySQL (Connector/J),最终将添加 SQL Server 支持 (jTDS);我们不太可能支持任何其他数据库.

We are using MySQL (Connector/J) and will eventually be adding SQL Server support (jTDS); it's unlikely that we'll support any other databases.

请参阅下面关于我试图消除连接池库的评论.似乎 DBCP 仍然相关(注意一些评论者推荐 C3P0 而不是 DBCP).

See comment below about my attempt to eliminate the connection pooling library. It appears that DBCP is still relevant (note that some commenters recommended C3P0 over DBCP).

推荐答案

在其他发帖人的鼓励下,我尝试取消 DBCP,直接使用 MySQL JDBC 驱动程序 (Connector/J 5.0.4).我无法这样做.

Based on the encouragement of other posters, I attempted to eliminate DBCP and use the MySQL JDBC driver directly (Connector/J 5.0.4). I was unable to do so.

虽然驱动程序确实提供了池化的基础,但它并没有提供最重要的东西:一个实际的池(源代码为此派上了用场).这部分由应用服务器提供.

It appears that while the driver does provide a foundation for pooling, it does not provide the most important thing: an actual pool (the source code came in handy for this). It is left up to the application server to provide this part.

我又看了看 JDBC 3.0 文档(我有一份标有第 11 章连接池"的打印副本,不确定它的确切来源),我可以看到 MySQL 驱动程序遵循 JDBC 文档.

I took another look at the JDBC 3.0 documentation (I have a printed copy of something labeled "Chapter 11 Connection Pooling", not sure exactly where it came from) and I can see that the MySQL driver is following the JDBC doc.

当我查看 DBCP 时,这个决定开始变得有意义了.良好的池管理提供了许多选择.例如,何时清除未使用的连接?你清除哪些连接?池中的最大连接数是否有硬或软限制?在将连接提供给呼叫者之前,您应该测试连接的活跃度"吗?等

When I look at DBCP, this decision starts to make sense. Good pool management provides many options. For example, when do you purge unused connection? which connections do you purge? is there a hard or soft limit on the max number of connections in the pool? should you test a connection for "liveness" before giving it to a caller? etc.

总结:如果你在做一个独立的Java应用程序,你需要使用一个连接池库.连接池库仍然相关.

Summary: if you're doing a standalone Java application, you need to use a connection pooling library. Connection pooling libraries are still relevant.

这篇关于DBCP(Apache Commons 数据库连接池)是否仍然相关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆