Where "ds" is a BoneCPDataSource initialized as follows:
final BoneCPDataSource ds = new BoneCPDataSource();
ds.setJdbcUrl("...");
ds.setUser("...");
ds.setPassword("...");
ds.setCloseConnectionWatch(true);
ds.setCloseConnectionWatchTimeout(1, TimeUnit.MINUTES);
Here is how I'm using it throughout my code:
try (Connection c = ds.getConnection()) {
// do stuff with c, this takes 10 seconds at most
c.commit();
} catch (final Exception e) {
logger.error("Report error", e);
}
But I'm seeing these:
WARNING: BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance. Mar 23, 2012 9:55:17 AM com.jolbox.bonecp.ConnectionPartition$1 finalizeReferent
It seems that the connection's finalizer is being called without the connection being closed - but how could this be? Doesn't the try-with-resource guarantee that the connection gets closed?
Then after this I start getting these errors:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Is there some way to get boneCP to show me a stacktrace where these finalized unclosed exceptions are being created? Can anyone suggest what the problem might be?