1 秒以内に多くのConnection
リクエストを起動し、プールのボトルネックを確認するたびに SELECT を実行してから、interrupt()
.
私が見つけたのは、スタックトレースが c3p0 でのメルトダウンを示していても、connection
オブジェクトがキャッチされた後は問題なくダンディであるということでした。まさに今、私は彼らのソースをチェックしています。確かに、彼らは. 彼らは適切な警告さえ投げます:InterruptedException
awaitAvailable(..)
InterruptedException
WARNING: com.mchange.v2.resourcepool.BasicResourcePool@5bcf4b61 -- an attempt to checkout a resource was interrupted, and the pool is still live: some other thread must have either interrupted the Thread attempting checkout!
多くのあいまいな言葉の合間にはありますが、まだ生きていると言っています。解決しました。
とにかくここでテストです。
ComboPooledDataSource ds = new ComboPooledDataSource();
// testing with various pool sizes - same effect
ds.setMinPoolSize(1);
ds.setMaxPoolSize(5);
ds.setInitialPoolSize(2);
Thread connectingThread = new Thread() {
public void run() {
Connection cnxn = null;
while (true) {
try {
cnxn = ds.getConnection();
System.out.println("Got connection.);
executeQuery(cnxn);
} catch (SQLException e) {
System.out.println("Got exception.");
e.printStackTrace();
// SOLUTION:
Throwable cause = e.getCause();
if (cause instanceof InterruptedException) {
System.out.println("Caught InterruptedException! Cnxn is " + cnxn);
// note that cnxn is a com.mchange.v2.c3p0.impl.NewProxyConnection
// also note that it's perfectly healthy.
//
// You may either want to:
// a) use the cnxn to submit your the query
executeQuery(cnxn);
cnxn.close()
// b) handle a proper shutdown
cnxn.close();
}
break;
}
}
};
};
connectingThread.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) { e.printStackTrace(); }
connectingThread.interrupt();