Fixed #29 implement clean shutdown

pull/30/head
Brett Wooldridge 11 years ago
parent 06ba9ef3c3
commit a96b55308a

@ -59,6 +59,7 @@ public final class HikariPool implements HikariPoolMBean
private final boolean isAutoCommit; private final boolean isAutoCommit;
private final boolean jdbc4ConnectionTest; private final boolean jdbc4ConnectionTest;
private int transactionIsolation; private int transactionIsolation;
private volatile boolean shutdown;
private boolean debug; private boolean debug;
/** /**
@ -140,6 +141,11 @@ public final class HikariPool implements HikariPoolMBean
*/ */
Connection getConnection() throws SQLException Connection getConnection() throws SQLException
{ {
if (shutdown)
{
throw new SQLException("Pool has been shutdown");
}
try try
{ {
long timeout = configuration.getConnectionTimeout(); long timeout = configuration.getConnectionTimeout();
@ -203,7 +209,7 @@ public final class HikariPool implements HikariPoolMBean
*/ */
public void releaseConnection(IHikariConnectionProxy connectionProxy) public void releaseConnection(IHikariConnectionProxy connectionProxy)
{ {
if (!connectionProxy.isBrokenConnection()) if (!connectionProxy.isBrokenConnection() && !shutdown)
{ {
idleConnectionCount.incrementAndGet(); idleConnectionCount.incrementAndGet();
idleConnections.put(connectionProxy); idleConnections.put(connectionProxy);
@ -216,7 +222,18 @@ public final class HikariPool implements HikariPoolMBean
void shutdown() void shutdown()
{ {
// TODO: implement complete shutdown of the pool shutdown = true;
houseKeepingTimer.cancel();
while (true)
{
IHikariConnectionProxy connection = idleConnections.poll();
if (connection == null)
{
break;
}
closeConnection(connection);
}
} }
// *********************************************************************** // ***********************************************************************
@ -325,7 +342,7 @@ public final class HikariPool implements HikariPoolMBean
} }
backgroundFillQueued.set(false); backgroundFillQueued.set(false);
} }
}, 90/*ms*/); }, 100/*ms*/);
} }
break; break;
} }
@ -365,9 +382,12 @@ public final class HikariPool implements HikariPoolMBean
} }
} }
idleConnectionCount.incrementAndGet(); if (!shutdown)
totalConnections.incrementAndGet(); {
idleConnections.add(proxyConnection); idleConnectionCount.incrementAndGet();
totalConnections.incrementAndGet();
idleConnections.add(proxyConnection);
}
break; break;
} }
catch (Exception e) catch (Exception e)

Loading…
Cancel
Save