数据库连接匮乏
我使用的是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这是因为在循环 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.