From 398acad77ab63177d3ea41fa3f329d0192850ef2 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Thu, 27 Mar 2014 09:53:45 +0900 Subject: [PATCH 1/6] Change visibility. --- src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java index 1dfb5eadc..0b7068b76 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java @@ -24,7 +24,7 @@ */ public class MetricsTracker { - private static final Context NO_CONTEXT = new Context(); + protected static final Context NO_CONTEXT = new Context(); public static class Context { From 8430fce40d515ee4c8f1329c92f65f9ed7139701 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sat, 29 Mar 2014 16:21:26 +0900 Subject: [PATCH 2/6] Switch back to setting our own context class loader during code generation. --- .../com/zaxxer/hikari/proxy/JavassistProxyFactory.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java b/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java index 07dd15f13..7ca62efe9 100644 --- a/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java +++ b/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java @@ -49,8 +49,11 @@ public final class JavassistProxyFactory static { + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { + Thread.currentThread().setContextClassLoader(JavassistProxyFactory.class.getClassLoader()); + JavassistProxyFactory proxyFactoryFactory = new JavassistProxyFactory(); proxyFactoryFactory.modifyProxyFactory(); } @@ -59,6 +62,10 @@ public final class JavassistProxyFactory LoggerFactory.getLogger(JavassistProxyFactory.class).error("Fatal exception during proxy generation", e); throw new RuntimeException(e); } + finally + { + Thread.currentThread().setContextClassLoader(contextClassLoader); + } } /** From cf2f0b0be4340c1079d96edd74dd9120f86d5dcf Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sat, 29 Mar 2014 16:23:08 +0900 Subject: [PATCH 3/6] Fixed #51 fix logging string substitution parameter. --- src/main/java/com/zaxxer/hikari/HikariMBeanElf.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariMBeanElf.java b/src/main/java/com/zaxxer/hikari/HikariMBeanElf.java index d16810fc3..d4181832d 100644 --- a/src/main/java/com/zaxxer/hikari/HikariMBeanElf.java +++ b/src/main/java/com/zaxxer/hikari/HikariMBeanElf.java @@ -89,7 +89,7 @@ public static void unregisterMBeans(HikariConfig configuration, HikariPool pool) } else { - LOGGER.error("No registered MBean for {0}.", configuration.getPoolName()); + LOGGER.error("No registered MBean for {}.", configuration.getPoolName()); } } catch (Exception e) From f059d39aa693b2551440a8f5829ed073c927f322 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sat, 29 Mar 2014 17:41:56 +0900 Subject: [PATCH 4/6] Restore max lifetime check to getConnection() rather than only in the housekeeper thread. An extremely active pool may never find an idle connection in the housekeeper alone. --- src/main/java/com/zaxxer/hikari/HikariPool.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariPool.java b/src/main/java/com/zaxxer/hikari/HikariPool.java index b0ebab400..03211cfde 100644 --- a/src/main/java/com/zaxxer/hikari/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/HikariPool.java @@ -138,32 +138,34 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener Connection getConnection() throws SQLException { final long start = System.currentTimeMillis(); + final long maxLife = configuration.getMaxLifetime(); final Context context = metricsTracker.recordConnectionRequest(start); long timeout = configuration.getConnectionTimeout(); try { do { - IHikariConnectionProxy connectionProxy = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS); - if (connectionProxy == null) // We timed out... break and throw exception + IHikariConnectionProxy connection = connectionBag.borrow(timeout, TimeUnit.MILLISECONDS); + if (connection == null) // We timed out... break and throw exception { break; } - connectionProxy.unclose(); + connection.unclose(); - if (System.currentTimeMillis() - connectionProxy.getLastAccess() > 1000 && !isConnectionAlive(connectionProxy, timeout)) + final long now = System.currentTimeMillis(); + if ((now - connection.getCreationTime() > maxLife) || (now - connection.getLastAccess() > 1000 && !isConnectionAlive(connection, timeout))) { - closeConnection(connectionProxy); // Throw away the dead connection, try again + closeConnection(connection); // Throw away the dead connection, try again timeout -= (System.currentTimeMillis() - start); continue; } else if (leakDetectionThreshold > 0) { - connectionProxy.captureStack(leakDetectionThreshold, houseKeepingTimer); + connection.captureStack(leakDetectionThreshold, houseKeepingTimer); } - return connectionProxy; + return connection; } while (timeout > 0); From b626016544f015e1f5f7ba27ffe422e91f36eba0 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sat, 29 Mar 2014 19:52:39 +0900 Subject: [PATCH 5/6] Restore max lifetime check to getConnection() rather than only in the housekeeper thread. An extremely active pool may never find an idle connection in the housekeeper alone. --- src/main/java/com/zaxxer/hikari/HikariPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariPool.java b/src/main/java/com/zaxxer/hikari/HikariPool.java index 03211cfde..a4c08d2c3 100644 --- a/src/main/java/com/zaxxer/hikari/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/HikariPool.java @@ -154,7 +154,7 @@ Connection getConnection() throws SQLException connection.unclose(); final long now = System.currentTimeMillis(); - if ((now - connection.getCreationTime() > maxLife) || (now - connection.getLastAccess() > 1000 && !isConnectionAlive(connection, timeout))) + if ((maxLife > 0 && now - connection.getCreationTime() > maxLife) || (now - connection.getLastAccess() > 1000 && !isConnectionAlive(connection, timeout))) { closeConnection(connection); // Throw away the dead connection, try again timeout -= (System.currentTimeMillis() - start); From ec373755f8b23767261d899df2701d94891a458d Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sun, 30 Mar 2014 10:45:37 +0900 Subject: [PATCH 6/6] Updated change log --- CHANGES | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES b/CHANGES index 08b71b1f6..0020c7e11 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,11 @@ HikariCP Changes +Changes between 1.3.4 and 1.3.5 + + *) Fixed a regression in the Javassist code generation. + + *) Various bug fixes and minor enhancements. + Changes between 1.3.3 and 1.3.4 *) Added new property isolateInternalQueries used to control whether