From ba09a68fe19cc020883e0563c7e53036cf4fa772 Mon Sep 17 00:00:00 2001 From: Nitin Date: Mon, 1 Feb 2016 19:58:30 +0530 Subject: [PATCH] better thread names and log in validateNumerics() with poolName --- .../java/com/zaxxer/hikari/HikariConfig.java | 30 +++++++++---------- .../com/zaxxer/hikari/pool/HikariPool.java | 8 ++--- .../java/com/zaxxer/hikari/pool/PoolBase.java | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariConfig.java b/src/main/java/com/zaxxer/hikari/HikariConfig.java index be618cd6..ec0c2a26 100644 --- a/src/main/java/com/zaxxer/hikari/HikariConfig.java +++ b/src/main/java/com/zaxxer/hikari/HikariConfig.java @@ -761,6 +761,13 @@ public class HikariConfig implements HikariConfigMXBean public void validate() { + if (poolName == null) { + poolName = "HikariPool-" + POOL_NUMBER.getAndIncrement(); + } + else if (isRegisterMbeans && poolName.contains(":")) { + throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX"); + } + validateNumerics(); // treat empty property as null @@ -773,13 +780,6 @@ public class HikariConfig implements HikariConfigMXBean driverClassName = getNullIfEmpty(driverClassName); jdbcUrl = getNullIfEmpty(jdbcUrl); - if (poolName == null) { - poolName = "HikariPool-" + POOL_NUMBER.getAndIncrement(); - } - else if (isRegisterMbeans && poolName.contains(":")) { - throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX"); - } - // Check Data Source Options if (dataSource != null) { if (dataSourceClassName != null) { @@ -814,43 +814,43 @@ public class HikariConfig implements HikariConfigMXBean private void validateNumerics() { if (maxLifetime < 0) { - LOGGER.error("maxLifetime cannot be negative."); + LOGGER.error("{} - maxLifetime cannot be negative.", poolName); throw new IllegalArgumentException("maxLifetime cannot be negative."); } else if (maxLifetime > 0 && maxLifetime < TimeUnit.SECONDS.toMillis(30)) { - LOGGER.warn("maxLifetime is less than 30000ms, setting to default {}ms.", MAX_LIFETIME); + LOGGER.warn("{} - maxLifetime is less than 30000ms, setting to default {}ms.", poolName, MAX_LIFETIME); maxLifetime = MAX_LIFETIME; } if (idleTimeout != 0 && idleTimeout < TimeUnit.SECONDS.toMillis(10)) { - LOGGER.warn("idleTimeout is less than 10000ms, setting to default {}ms.", IDLE_TIMEOUT); + LOGGER.warn("{} - idleTimeout is less than 10000ms, setting to default {}ms.", poolName, IDLE_TIMEOUT); idleTimeout = IDLE_TIMEOUT; } if (idleTimeout + TimeUnit.SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) { - LOGGER.warn("idleTimeout is close to or more than maxLifetime, disabling it."); + LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", poolName); idleTimeout = 0; } if (maxLifetime == 0 && idleTimeout == 0) { - LOGGER.warn("setting idleTimeout to {}ms.", IDLE_TIMEOUT); + LOGGER.warn("{} - setting idleTimeout to {}ms.", poolName, IDLE_TIMEOUT); idleTimeout = IDLE_TIMEOUT; } if (leakDetectionThreshold > 0 && !unitTest) { if (leakDetectionThreshold < TimeUnit.SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) { - LOGGER.warn("leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it."); + LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName); leakDetectionThreshold = 0L; } } if (connectionTimeout != Integer.MAX_VALUE) { if (validationTimeout > connectionTimeout) { - LOGGER.warn("validationTimeout should be less than connectionTimeout, setting validationTimeout to connectionTimeout."); + LOGGER.warn("{} - validationTimeout should be less than connectionTimeout, setting validationTimeout to connectionTimeout.", poolName); validationTimeout = connectionTimeout; } if (maxLifetime > 0 && connectionTimeout > maxLifetime) { - LOGGER.warn("connectionTimeout should be less than maxLifetime, setting connectionTimeout to maxLifetime."); + LOGGER.warn("{} - connectionTimeout should be less than maxLifetime, setting connectionTimeout to maxLifetime.", poolName); connectionTimeout = maxLifetime; } } diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 477f629a..fd376dad 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -116,11 +116,11 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL checkFailFast(); ThreadFactory threadFactory = config.getThreadFactory(); - this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection adder (" + poolName + ")", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); - this.closeConnectionExecutor = createThreadPoolExecutor(1 + (config.getMaximumPoolSize() / 2), "Hikari connection closer (" + poolName + ")", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); + this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), poolName + " connection adder", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); + this.closeConnectionExecutor = createThreadPoolExecutor(1 + (config.getMaximumPoolSize() / 2), poolName + " connection closer", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); if (config.getScheduledExecutorService() == null) { - threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("Hikari housekeeper (" + poolName + ")", true); + threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory(poolName + " housekeeper", true); this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy()); this.houseKeepingExecutorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.houseKeepingExecutorService.setRemoveOnCancelPolicy(true); @@ -223,7 +223,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL connectionBag.close(); - final ExecutorService assassinExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection assassin (" + poolName + ")", + final ExecutorService assassinExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), poolName + " connection assassinator", config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); try { final long start = clockSource.currentTime(); diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 10d45c15..fdd40570 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -485,7 +485,7 @@ abstract class PoolBase } else { ThreadFactory threadFactory = config.getThreadFactory(); - threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("Hikari network timeout executor (" + poolName + ")", true); + threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory(poolName + " network timeout executor", true); ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(threadFactory); executor.setKeepAliveTime(15, TimeUnit.SECONDS); executor.allowCoreThreadTimeOut(true);