BoneCP无法从断开的连接中恢复 [英] BoneCP doesn't recover from broken connection
问题描述
我对BoneCP(0.7.1 RELEASE)有问题.尽管BoneCP.getConnection()
可以确保假定DB处于活动状态,但它仍将返回Connection对象.
I have a problem with BoneCP (0.7.1 RELEASE). I though that BoneCP.getConnection()
ensures it would return Connection object assuming that DB is alive.
这是我配置池的方式
private void setupConnectionPool() throws SQLException
{
// setup the connection pool
String connectUri = "jdbc:mysql://master-mysql:3306/base?zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&useCompression=true";
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(connectUri);
config.setUsername("dbapp");
config.setPassword("meh");
config.setMinConnectionsPerPartition(5);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
config.setConnectionTimeoutInMs(5 * 1000);
this.connectionPool = new BoneCP(config); // setup the connection pool
}
然后在代码中的某个地方像这样使用它
then somewhere in the code I use it like this
// I'm using Apache DbUtils
QueryRunner run = new QueryRunner();
Object result = run.query(this.connectionPool.getConnection(), query, handler, start, limit);
试图运行此查询会引发状态为08S01
(通信链接失败)的SQLException
.
Attempt to run this query throws SQLException
with state 08S01
(Communications link failure).
随后对this.connectionPool.getConnection()
的调用将返回良好的连接.
Subsequent call to this.connectionPool.getConnection()
returns good connection.
但这不是连接池的全部内容,这样我就不必自己处理丢失连接的情况了吗?
But isn't it a whole point of connection pool so that I don't have to handle cases of lost connection myself?
推荐答案
-
它应该捕获08S01并清除池中的所有连接.但是,如果您有多个线程,则您的线程可能已经签出了一个连接,该连接可能会失败(其余连接应再次变为OK).
It should capture 08S01 and wipe out all the connections in the pool. However if you have multiple threads, you might have a thread that has already checked out a connection which might fail (the rest of the connections should become OK again).
请尝试0.8.0-beta3-SNAPSHOT;我最近清理了该实现,并添加了一些健壮性测试来测试各种场景,其中包括08S01.
Please try out 0.8.0-beta3-SNAPSHOT; I have very recently cleaned up that implementation and added a bunch of robustness tests testing out various scenarios, amongst them, 08S01.
这篇关于BoneCP无法从断开的连接中恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!