From 5ea5688db367f880141e2b330e2ea7538aabc1e9 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Wed, 7 Jan 2015 12:53:14 +0900 Subject: [PATCH] Start the housekeeping thread first run after the default interval (30 seconds) rather than hardcoded 10 seconds. --- .../main/java/com/zaxxer/hikari/pool/BaseHikariPool.java | 2 +- .../com/zaxxer/hikari/TestConnectionTimeoutRetry.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hikaricp-common/src/main/java/com/zaxxer/hikari/pool/BaseHikariPool.java b/hikaricp-common/src/main/java/com/zaxxer/hikari/pool/BaseHikariPool.java index 252c5d8f..cc7cc78f 100644 --- a/hikaricp-common/src/main/java/com/zaxxer/hikari/pool/BaseHikariPool.java +++ b/hikaricp-common/src/main/java/com/zaxxer/hikari/pool/BaseHikariPool.java @@ -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); diff --git a/hikaricp-common/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java b/hikaricp-common/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java index 1c585f1d..b3b5f176 100644 --- a/hikaricp-common/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java +++ b/hikaricp-common/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java @@ -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(); } }