一旦达到 acquireRetryAttempts,c3p0 getConnection 不会返回或抛出异常
在我的连接池中使用 c3p0,在连接池耗尽其重试尝试后,调用 c3p0 的线程似乎被终止或处于未定义状态。
连接池的定义如下:
private val pool = new ComboPooledDataSource
pool.setDriverClass(config("database.driverClass").as[String])
pool.setJdbcUrl(config("database.jdbcUrl").as[String])
pool.setUser(config("database.user").as[String])
pool.setPassword(config("database.password").as[String])
pool.setAcquireRetryAttempts(5)
客户端代码调用 getConnection,它会在 c3p0 旋转连接重试尝试时短暂阻塞。奇怪的是,它似乎并没有真正从这个调用中返回。从文档中,我预计会抛出异常:
If all attempts fail, any clients waiting for Connections from the
DataSource will see an Exception, indicating that a Connection
could not be acquired
这非常奇怪。它肯定不会返回,也不会抛出异常。从每 5 秒运行一次的 Executors.newSingleThreadScheduledExecutor 调用 getConnection 的客户端代码。当对 getConnection 的调用似乎消失时,调度的执行程序线程似乎也完全停止执行。
在本例中,我故意关闭数据库,以便我可以弄清楚这里发生了什么。有什么想法吗?
更新:奇怪的是,如果我不使用计划的执行程序,而是在我自己的监视器线程中运行它,#getConnection 将按预期执行。
Using c3p0 for my connection pool, the thread calling c3p0 appears to be terminated or left in an undefined state after the connection pool exhausts its retry attempts.
The connection pool is defined as such:
private val pool = new ComboPooledDataSource
pool.setDriverClass(config("database.driverClass").as[String])
pool.setJdbcUrl(config("database.jdbcUrl").as[String])
pool.setUser(config("database.user").as[String])
pool.setPassword(config("database.password").as[String])
pool.setAcquireRetryAttempts(5)
The client code calls getConnection, which blocks briefly while c3p0 spins through the connection retry attempts. The strange thing is that it doesn't really seem to return back from this call. From the documentation, I expected an Exception to be thrown:
If all attempts fail, any clients waiting for Connections from the
DataSource will see an Exception, indicating that a Connection
could not be acquired
It's very bizarre. It definitely does not return, and it does not throw an Exception.The client code that is calling getConnection from a Executors.newSingleThreadScheduledExecutor that runs every 5 seconds. When the call to getConnection seems to evaporate, the scheduled executor thread also seems to stop executing at all.
In this case I'm intentionally leaving the database off so that I can figure out what's going on here. Any ideas?
UPDATE: Strangely enough, if I don't use a scheduled executor and instead run it in my own monitor thread, #getConnection performs as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论