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

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

问题描述

JDBC 3.0规范介绍了Connection(和Prepared Statement)池。

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(连接器/ 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章连接Pooling,不确定它来自哪里),我可以看到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天全站免登陆