Start the housekeeping thread first run after the default interval (30 seconds) rather than hardcoded 10 seconds.

2.3.0
Brett Wooldridge 10 years ago
parent 684d0683e9
commit 5ea5688db3

@ -153,7 +153,7 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
long delayPeriod = Long.getLong("com.zaxxer.hikari.housekeeping.periodMs", TimeUnit.SECONDS.toMillis(30L));
ThreadFactory threadFactory = configuration.getThreadFactory() != null ? configuration.getThreadFactory() : new DefaultThreadFactory("Hikari Housekeeping Timer (pool " + configuration.getPoolName() + ")", true);
this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
this.houseKeepingExecutorService.scheduleAtFixedRate(getHouseKeeper(), TimeUnit.SECONDS.toMillis(10L), delayPeriod, TimeUnit.MILLISECONDS);
this.houseKeepingExecutorService.scheduleAtFixedRate(getHouseKeeper(), delayPeriod, delayPeriod, TimeUnit.MILLISECONDS);
this.leakTask = (configuration.getLeakDetectionThreshold() == 0) ? LeakTask.NO_LEAK : new LeakTask(configuration.getLeakDetectionThreshold(), houseKeepingExecutorService);
setRemoveOnCancelPolicy(houseKeepingExecutorService);

@ -221,10 +221,10 @@ public class TestConnectionTimeoutRetry
config.setMinimumIdle(5);
config.setMaximumPoolSize(10);
config.setConnectionTimeout(1000);
config.setConnectionTestQuery("VALUES 1");
config.setConnectionTestQuery("VALUES 2");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "100");
System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "500");
HikariDataSource ds = new HikariDataSource(config);
@ -237,7 +237,7 @@ public class TestConnectionTimeoutRetry
Connection connection6 = ds.getConnection();
Connection connection7 = ds.getConnection();
Thread.sleep(1500);
Thread.sleep(1200);
Assert.assertSame("Totals connections not as expected", 10, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 3, TestElf.getPool(ds).getIdleConnections());
@ -254,7 +254,7 @@ public class TestConnectionTimeoutRetry
Assert.assertSame("Idle connections not as expected", 10, TestElf.getPool(ds).getIdleConnections());
}
finally {
System.getProperties().remove("com.zaxxer.hikari.housekeeping.periodMs", "100");
System.getProperties().remove("com.zaxxer.hikari.housekeeping.periodMs");
ds.close();
}
}

Loading…
Cancel
Save