diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 7aba89dc1..3eec7908d 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -45,7 +45,7 @@ import com.zaxxer.hikari.util.ClockSource; import com.zaxxer.hikari.util.ConcurrentBag; import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener; -import com.zaxxer.hikari.util.DefaultThreadFactory; +import com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory; import com.zaxxer.hikari.util.SuspendResumeLock; import static com.zaxxer.hikari.pool.PoolEntry.LASTACCESS_COMPARABLE; @@ -104,11 +104,12 @@ public HikariPool(final HikariConfig config) this.totalConnections = new AtomicInteger(); this.suspendResumeLock = config.isAllowPoolSuspension() ? new SuspendResumeLock() : SuspendResumeLock.FAUX_LOCK; - this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection adder (pool " + poolName + ")", config.getThreadFactory(), new ThreadPoolExecutor.DiscardPolicy()); - this.closeConnectionExecutor = createThreadPoolExecutor(4, "Hikari connection closer (pool " + poolName + ")", config.getThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); + ThreadFactory threadFactory = config.getThreadFactory(); + this.addConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), "Hikari connection adder (pool " + poolName + ")", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); + this.closeConnectionExecutor = createThreadPoolExecutor(4, "Hikari connection closer (pool " + poolName + ")", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); if (config.getScheduledExecutorService() == null) { - ThreadFactory threadFactory = config.getThreadFactory() != null ? config.getThreadFactory() : new DefaultThreadFactory("Hikari housekeeper (pool " + poolName + ")", true); + threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("Hikari housekeeper (pool " + poolName + ")", true); this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy()); this.houseKeepingExecutorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.houseKeepingExecutorService.setRemoveOnCancelPolicy(true); diff --git a/src/main/java/com/zaxxer/hikari/util/DefaultThreadFactory.java b/src/main/java/com/zaxxer/hikari/util/DefaultThreadFactory.java deleted file mode 100644 index 2db11b3ab..000000000 --- a/src/main/java/com/zaxxer/hikari/util/DefaultThreadFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2013, 2014 Brett Wooldridge - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zaxxer.hikari.util; - -import java.util.concurrent.ThreadFactory; - -public class DefaultThreadFactory implements ThreadFactory { - - private final String threadName; - private final boolean daemon; - - public DefaultThreadFactory(String threadName, boolean daemon) { - this.threadName = threadName; - this.daemon = daemon; - } - - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r, threadName); - thread.setDaemon(daemon); - return thread; - } -} diff --git a/src/main/java/com/zaxxer/hikari/util/UtilityElf.java b/src/main/java/com/zaxxer/hikari/util/UtilityElf.java index b9d8a7b59..b3d6a4657 100644 --- a/src/main/java/com/zaxxer/hikari/util/UtilityElf.java +++ b/src/main/java/com/zaxxer/hikari/util/UtilityElf.java @@ -150,4 +150,22 @@ public static int getTransactionIsolation(final String transactionIsolationName) return -1; } + + public static final class DefaultThreadFactory implements ThreadFactory { + + private final String threadName; + private final boolean daemon; + + public DefaultThreadFactory(String threadName, boolean daemon) { + this.threadName = threadName; + this.daemon = daemon; + } + + @Override + public Thread newThread(Runnable r) { + Thread thread = new Thread(r, threadName); + thread.setDaemon(daemon); + return thread; + } + } }