数据库连接自动重新连接
我在 Tomcat 中有一个 DBCP 连接池。问题是,当连接短暂丢失时,应用程序就会中断,因为 DBCP 不会在稍后有连接时尝试再次重新连接。我可以让 DBCP 自动重新连接吗?
I have a DBCP connection pool in Tomcat. The problem is that when the connection is lost briefly the appliction is broken because DBCP won't try to reconnect again later when there is a connection. Can I get DBCP to reconnect automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法可以“解决”这个问题,尽管两者都有一些问题:
您可以使用“validationQuery”(见下文)在开始之前运行测试查询(通常类似于“select 1 from Dual”,其中将用于在将连接获取/提供给池之前/之后测试连接。这会为池中的每个连接请求添加一个额外的调用。 “ rel="noreferrer">http://wiki.apache.org/commons/DBCP
您可以让idleEvictorThread 通过设置testWhileIdle 来执行此操作,而不是每个查询都执行此操作,但在某些版本中,该线程可能会在高负载下导致死锁。请参阅:http://commons.apache.org/dbcp/configuration.html 了解更多信息有关该选项和其他选项的详细信息
There are 2 ways to "solve" this, though both have some issues:
You can use a "validationQuery" (see below) to have a test query run before you go (generally something like 'select 1 from dual' which will be used to test connections before/after you get/give them to the pool. This adds an extra call per connection request from the pool. See: http://wiki.apache.org/commons/DBCP
Instead of doing this per query, you can have the idleEvictorThread do it by setting testWhileIdle, though in some versions that thread can cause deadlocking under high-load. See: http://commons.apache.org/dbcp/configuration.html for more details on that and other options
不要认为 DBCP 会这样做,但 BoneCP (http://jolbox.com) 可以配置为自动重播任何内容当数据库或网络出现故障时进行事务处理。它对您的应用程序是完全透明的。
Don't think DBCP does that, but BoneCP (http://jolbox.com) can be configured to automatically replay any transactions when the DB or network goes down. It's completely transparent to your application.