数据库连接自动重新连接

发布于 2024-08-27 07:45:30 字数 97 浏览 18 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

塔塔猫 2024-09-03 07:45:30

有两种方法可以“解决”这个问题,尽管两者都有一些问题:

  1. 您可以使用“validationQuery”(见下文)在开始之前运行测试查询(通常类似于“select 1 from Dual”,其中将用于在将连接获取/提供给池之前/之后测试连接。这会为池中的每个连接请求添加一个额外的调用。 “ rel="noreferrer">http://wiki.apache.org/commons/DBCP

  2. 您可以让idleEvictorThread 通过设置testWhileIdle 来执行此操作,而不是每个查询都执行此操作,但在某些版本中,该线程可能会在高负载下导致死锁。请参阅:http://commons.apache.org/dbcp/configuration.html 了解更多信息有关该选项和其他选项的详细信息

There are 2 ways to "solve" this, though both have some issues:

  1. 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

  2. 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

绅刃 2024-09-03 07:45:30

不要认为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文