do not add cons if pool is not normal, avoid exceptions in shutdown

pull/496/head
Nitin 10 years ago
parent ce1545bb39
commit 4847a653f2

@ -213,8 +213,6 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
LOGGER.info("{} - is closing down.", poolName); LOGGER.info("{} - is closing down.", poolName);
logPoolState("Before closing\t"); logPoolState("Before closing\t");
connectionBag.close();
softEvictConnections();
addConnectionExecutor.shutdown(); addConnectionExecutor.shutdown();
addConnectionExecutor.awaitTermination(5L, TimeUnit.SECONDS); addConnectionExecutor.awaitTermination(5L, TimeUnit.SECONDS);
if (config.getScheduledExecutorService() == null) { if (config.getScheduledExecutorService() == null) {
@ -222,6 +220,8 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
houseKeepingExecutorService.awaitTermination(5L, TimeUnit.SECONDS); houseKeepingExecutorService.awaitTermination(5L, TimeUnit.SECONDS);
} }
connectionBag.close();
final ExecutorService assassinExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection assassin", final ExecutorService assassinExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection assassin",
config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
try { try {
@ -561,7 +561,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
public Boolean call() throws Exception public Boolean call() throws Exception
{ {
long sleepBackoff = 200L; long sleepBackoff = 200L;
while (totalConnections.get() < config.getMaximumPoolSize()) { while (poolState == POOL_NORMAL && totalConnections.get() < config.getMaximumPoolSize()) {
final PoolEntry poolEntry = createPoolEntry(); final PoolEntry poolEntry = createPoolEntry();
if (poolEntry != null) { if (poolEntry != null) {
totalConnections.incrementAndGet(); totalConnections.incrementAndGet();
@ -573,7 +573,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
quietlySleep(sleepBackoff); quietlySleep(sleepBackoff);
sleepBackoff = Math.min(connectionTimeout / 2, (long) (sleepBackoff * 1.3)); sleepBackoff = Math.min(connectionTimeout / 2, (long) (sleepBackoff * 1.3));
} }
// Pool is at max size // Pool is suspended or shutdown or at max size
return Boolean.FALSE; return Boolean.FALSE;
} }
} }

@ -87,13 +87,13 @@ public class ShutdownTest
UtilityElf.quietlySleep(1200L); UtilityElf.quietlySleep(1200L);
Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() > 0); Assert.assertTrue("Total connection count not as expected, ", pool.getTotalConnections() > 0);
ds.close(); ds.close();
Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections()); Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections()); Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections()); Assert.assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
Assert.assertTrue(ds.isClosed()); Assert.assertTrue(ds.isClosed());
} }
@ -116,13 +116,13 @@ public class ShutdownTest
UtilityElf.quietlySleep(1200L); UtilityElf.quietlySleep(1200L);
Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() > 0); Assert.assertTrue("Total connection count not as expected, ", pool.getTotalConnections() > 0);
ds.close(); ds.close();
Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections()); Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections()); Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections()); Assert.assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
Assert.assertTrue(ds.toString().startsWith("HikariDataSource (") && ds.toString().endsWith(")")); Assert.assertTrue(ds.toString().startsWith("HikariDataSource (") && ds.toString().endsWith(")"));
} }
@ -145,13 +145,13 @@ public class ShutdownTest
UtilityElf.quietlySleep(1200L); UtilityElf.quietlySleep(1200L);
Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() == 5); Assert.assertTrue("Total connection count not as expected, ", pool.getTotalConnections() == 5);
ds.close(); ds.close();
Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections()); Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections()); Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections()); Assert.assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
} }
@Test @Test
@ -200,13 +200,13 @@ public class ShutdownTest
connections[i] = ds.getConnection(); connections[i] = ds.getConnection();
} }
Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() == 5); Assert.assertTrue("Total connection count not as expected, ", pool.getTotalConnections() == 5);
ds.close(); ds.close();
Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections()); Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections()); Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections()); Assert.assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
} }
@Test @Test

Loading…
Cancel
Save