数据库连接匮乏

发布于 2024-12-20 06:25:29 字数 350 浏览 4 评论 0原文

我使用的是Spring 2.5;使用 apache-commons-dbcp 连接池的 SimpleJdbcTemplate。还有一个线程池,它在运行查询时生成一个线程(执行多个查询,并在所有查询完成后处理它们的结果,因此生成线程以并行运行查询)。

最终,所有线程都在 TIMED_WAIT 中等待 getConnection()。似乎没有线程获得连接。我检查了数据库,连接全部空闲。

是什么原因造成的?我有 10 个连接作为最大池大小和 50-100 个线程。我应该如何配置这个? DBA 说应该有足够的连接(我同意,因为它们都是空闲的)。

当 BoneCP 作为 SimpleJdbcTemplate 的数据源时,也会发生同样的情况。

I am using Spring 2.5; a SimpleJdbcTemplate using apache-commons-dbcp connection pooling. There is also a thread pool which spawns a thread when a query is run (several queries are performed and their results processed once all are complete, so the threads are spawned to run queries in parallel).

Eventually, all the threads are waiting on getConnection() in a TIMED_WAIT. No thread seems to get a Connection. I check the DB and the connections are all idle.

What is causing this? I have 10 connections as the max Pool size and 50-100 threads. How should I be configuring this? The DBA says that should be enough connections (and I agree since they are all idle).

The same thing happens with BoneCP as the datasource for the SimpleJdbcTemplate as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

胡渣熟男 2024-12-27 06:25:29

事实证明,这是因为在循环 ResultSet 的过程中,启动了另一个查询,因此,如果第一个查询足够多,第二个查询就无法获得连接,一切都陷入死锁。

Turns out it was because in the middle of looping through a ResultSet, another query was started, so with enough first queries, the second ones cannot get a connection and everything deadlocks.

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