diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 984adb3f..51ae4ada 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -314,18 +314,18 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener final int maxPoolSize = configuration.getMaximumPoolSize(); final int minIdle = configuration.getMinimumIdle(); while (!isShutdown && totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle)) { - if (!addConnection()) { + if (addConnection()) { + if (minIdle == 0) { + break; // This break is here so we only add one connection when there is no min. idle + } + } + else { if (minIdle == 0 && getThreadsAwaitingConnection() == 0) { break; } quietlySleep(sleepBackoff); sleepBackoff = Math.min(connectionTimeout / 2, (long) ((double) sleepBackoff * 1.5)); - continue; - } - - if (minIdle == 0) { - break; // This break is here so we only add one connection when there is no min. idle } } } diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java index 597feeb8..7c014cb2 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java @@ -231,22 +231,21 @@ public final class PoolUtilities */ public static boolean isJdbc40Compliant(final Connection connection) throws SQLException { - if (jdbc40checked) { - return IS_JDBC40; - } - - try { - connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver - IS_JDBC40 = true; - } - catch (AbstractMethodError e) { - IS_JDBC40 = false; - } - catch (SQLFeatureNotSupportedException e) { - IS_JDBC40 = false; + if (!jdbc40checked) { + jdbc40checked = true; + + try { + connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver + IS_JDBC40 = true; + } + catch (SQLFeatureNotSupportedException e) { + IS_JDBC40 = false; + } + catch (AbstractMethodError e) { + IS_JDBC40 = false; + } } - - jdbc40checked = true; + return IS_JDBC40; } @@ -259,22 +258,21 @@ public final class PoolUtilities */ public static boolean isJdbc41Compliant(final Connection connection) throws SQLException { - if (jdbc41checked) { - return IS_JDBC41; - } + if (!jdbc41checked) { + jdbc41checked = true; - try { - connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver - IS_JDBC41 = true; - } - catch (AbstractMethodError e) { - IS_JDBC41 = false; - } - catch (SQLFeatureNotSupportedException e) { - IS_JDBC41 = false; + try { + connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver + IS_JDBC41 = true; + } + catch (AbstractMethodError e) { + IS_JDBC41 = false; + } + catch (SQLFeatureNotSupportedException e) { + IS_JDBC41 = false; + } } - jdbc41checked = true; return IS_JDBC41; } @@ -313,19 +311,18 @@ public final class PoolUtilities */ public static int setNetworkTimeout(final Executor executor, final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout) throws SQLException { - if (!isUseNetworkTimeout) { - return 0; + if (isUseNetworkTimeout) { + try { + final int networkTimeout = connection.getNetworkTimeout(); + connection.setNetworkTimeout(executor, (int) timeoutMs); + return networkTimeout; + } + catch (SQLFeatureNotSupportedException e) { + IS_JDBC41 = false; + } } - try { - final int networkTimeout = connection.getNetworkTimeout(); - connection.setNetworkTimeout(executor, (int) timeoutMs); - return networkTimeout; - } - catch (SQLFeatureNotSupportedException e) { - IS_JDBC41 = false; - return 0; - } + return 0; } /** diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/hikaricp/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 1087ad40..5468f021 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -308,18 +308,18 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener final int maxPoolSize = configuration.getMaximumPoolSize(); final int minIdle = configuration.getMinimumIdle(); while (!isShutdown && totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle)) { - if (!addConnection()) { + if (addConnection()) { + if (minIdle == 0) { + break; // This break is here so we only add one connection when there is no min. idle + } + } + else { if (minIdle == 0 && getThreadsAwaitingConnection() == 0) { break; } quietlySleep(sleepBackoff); sleepBackoff = Math.min(connectionTimeout / 2, (long) ((double) sleepBackoff * 1.5)); - continue; - } - - if (minIdle == 0) { - break; // This break is here so we only add one connection when there is no min. idle } } }); diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java b/hikaricp/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java index b10058c6..56c912be 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/util/PoolUtilities.java @@ -213,19 +213,18 @@ public final class PoolUtilities */ public static boolean isJdbc40Compliant(final Connection connection) throws SQLException { - if (jdbc40checked) { - return IS_JDBC40; - } - - try { - connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver - IS_JDBC40 = true; - } - catch (AbstractMethodError | SQLFeatureNotSupportedException e) { - IS_JDBC40 = false; + if (!jdbc40checked) { + jdbc40checked = true; + + try { + connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver + IS_JDBC40 = true; + } + catch (AbstractMethodError | SQLFeatureNotSupportedException e) { + IS_JDBC40 = false; + } } - - jdbc40checked = true; + return IS_JDBC40; } @@ -238,19 +237,18 @@ public final class PoolUtilities */ public static boolean isJdbc41Compliant(final Connection connection) throws SQLException { - if (jdbc41checked) { - return IS_JDBC41; - } + if (!jdbc41checked) { + jdbc41checked = true; - try { - connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver - IS_JDBC41 = true; - } - catch (AbstractMethodError | SQLFeatureNotSupportedException e) { - IS_JDBC41 = false; + try { + connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver + IS_JDBC41 = true; + } + catch (AbstractMethodError | SQLFeatureNotSupportedException e) { + IS_JDBC41 = false; + } } - jdbc41checked = true; return IS_JDBC41; } @@ -286,19 +284,18 @@ public final class PoolUtilities */ public static int setNetworkTimeout(final Executor executor, final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout) throws SQLException { - if (!isUseNetworkTimeout) { - return 0; + if (isUseNetworkTimeout) { + try { + final int networkTimeout = connection.getNetworkTimeout(); + connection.setNetworkTimeout(executor, (int) timeoutMs); + return networkTimeout; + } + catch (SQLFeatureNotSupportedException e) { + IS_JDBC41 = false; + } } - try { - final int networkTimeout = connection.getNetworkTimeout(); - connection.setNetworkTimeout(executor, (int) timeoutMs); - return networkTimeout; - } - catch (SQLFeatureNotSupportedException e) { - IS_JDBC41 = false; - return 0; - } + return 0; } /**