I am using hikaricp (this would probably apply to any other Database connection pool as well). I have a DBPool class in which I instantiate a HikariDataSource (using the HikariConfig object). I am using the lazy holder idiom for this DBPool to limit one pool instance per VM. However, once you get a reference to the pool, you can retrieve the Connection object (without any further locks/synchronization/semaphore checks) since I thought the connection pool would take care of my connection object limits. Evertime I get the connection reference via the DBPool, I call close on the connection/preparedstatement/resultset. I could try a try with resources if that's causing an issue. I am observing the following in the logs:
2014-09-14 18:53:25,302 WARN c.z.h.p.LeakTask [Hikari Housekeeping Timer (pool testHikariCp)] Connection leak detection triggered, stack trace follows java.lang.Exception
at com.akkadian.db.DBConnPool.getConnection(DBConnPool.java:67)
at models.tester.storeload.testAlertLogStoreLoad.loadAll(testAlertChk.java:101)
at com.testLib.map.MapStoreWrapper.loadAll(MapStoreWrapper.java:131)
at com.testLib.map.mapstore.AbstractMapDataStore.loadAll(AbstractMapDataStore.java:40)
at com.testLib.map.BasicRecordStoreLoader$MapLoadAllTask.run(BasicRecordStoreLoader.java:340)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.testLib.util.executor.CompletableFutureTask.run(CompletableFutureTask.java:57)
at com.testLib.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:209)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at com.testLib.util.executor.testLibManagedThread.executeRun(testLibManagedThread.java:76)
at com.testLib.util.executor.testLibManagedThread.run(testLibManagedThread.java:92)
I increased the connection timeout and set the leakDetectionthreshold as follows:
hikariConfig.setConnectionTimeout(90000);
hikariConfig.setLeakDetectionThreshold(10000);
I also increased the size of the pool even though it was recommended not to - I had to test various options since I was receiving connection timeouts from the database.
Make sure that you are indeed releasing the connection back to the pool? Can you use try with resources (in addition to increasing threshold as Brett mentioned):
try (Connection conn = DBConnectionPool.getConnection();
PreparedStatement ps = conn.prepareStatement(preparedQuery);) {
and the resultset (because some drivers/databases may not clean out resultset when connection is cleaned though not sure if this is still valid for new drivers/databases but I'm not sure what you are using):
try (ResultSet rs = ps.executeQuery();) {
Increase the leak detection threshold if needed though I think if you have to make it too large, you have an issue which needs to be fixed.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments