Fix #76 avoid possible thread leak on shutdown

pull/77/head
Johannes Herr 11 years ago
parent ed7234793b
commit a89f52c1de

@ -295,7 +295,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
int sleepBackoff = 200;
final int maxPoolSize = configuration.getMaximumPoolSize();
final int minIdle = configuration.getMinimumIdle();
while (totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle))
while (!isShutdown && totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle))
{
if (!addConnection())
{

@ -16,6 +16,8 @@
package com.zaxxer.hikari;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
@ -149,4 +151,36 @@ public class ShutdownTest
Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections());
}
@Test
public void testShutdown4() throws SQLException
{
int threadCountStart = threadCount();
StubConnection.slowCreate = true;
HikariConfig config = new HikariConfig();
config.setMinimumIdle(10);
config.setMaximumPoolSize(10);
config.setInitializationFailFast(false);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
HikariDataSource ds = new HikariDataSource(config);
PoolUtilities.quietlySleep(300);
ds.shutdown();
PoolUtilities.quietlySleep(700);
int threadCountEnd = threadCount();
Assert.assertSame("Thread was leaked", threadCountStart, threadCountEnd);
}
private int threadCount() {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
return threadMXBean.getThreadCount();
}
}

Loading…
Cancel
Save