From 8cc12140079224184f6db1ae0313aa05a9c7e69a Mon Sep 17 00:00:00 2001 From: Nitin Date: Fri, 14 Aug 2015 11:45:28 +0530 Subject: [PATCH] close connections marked for eviction first --- CHANGES | 11 ++++++++++- .../com/zaxxer/hikari/pool/HikariPool.java | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index bbe4f7c3..2fc5cf4e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,14 @@ HikariCP Changes + * issue 379: stop closing idle connections, to keep minIdle connections in pool + * issue 375: fixed InvalidPathException in HikariConfig + * issue 362: fixed NullPointerException in closing connection (closing statements) + * issue 357: allow altering the username & password through JMX at runtime + * issue 349: handle integer Transaction isolation level + * Throw SQLTransientConnectionException instead of SQLTimeoutException + * for validating connection, if network time out is set, do not set query timeout too + * ResultSet.getStatement() should return StatementProxy + Changes in 2.4.0 * Consolidated distribution into single JVM target (Java 7/8). Java 6 support has @@ -7,7 +16,7 @@ Changes in 2.4.0 * Removed runtime dependency on Javassist by pre-generating proxy classes at build-time. - * Significantly reduced overhead, and increased reliabilty, of ConcurrentBag. + * Significantly reduced overhead, and increased reliability, of ConcurrentBag. * Reduced garbage generation by 2-3x. diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 749659ce..2ef9edc4 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -631,15 +631,22 @@ public class HikariPool implements HikariPoolMXBean, IBagStateListener } logPoolState("Before cleanup "); - final List bag = connectionBag.values(STATE_NOT_IN_USE); + boolean evicted = false; + List bag = connectionBag.values(STATE_NOT_IN_USE); + for (PoolBagEntry bagEntry : bag) { + if (bagEntry.evicted) { + closeConnection(bagEntry, "(connection evicted)"); + evicted = true; + } + } + if (evicted) { + //get fresh bag + bag = connectionBag.values(STATE_NOT_IN_USE); + } int removable = bag.size() - config.getMinimumIdle(); for (PoolBagEntry bagEntry : bag) { if (connectionBag.reserve(bagEntry)) { - if (bagEntry.evicted) { - closeConnection(bagEntry, "(connection evicted)"); - removable--; - } - else if (removable > 0 && idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) { + if (removable > 0 && idleTimeout > 0L && clockSource.elapsedMillis(bagEntry.lastAccess, now) > idleTimeout) { closeConnection(bagEntry, "(connection passed idleTimeout)"); removable--; }