Skip to content

Commit

Permalink
merged DefaultThreadFactory with UtilityElf
Browse files Browse the repository at this point in the history
  • Loading branch information
nitincchauhan committed Jan 7, 2016
1 parent cf1b773 commit 2f3a107
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 0 additions & 36 deletions src/main/java/com/zaxxer/hikari/util/DefaultThreadFactory.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/com/zaxxer/hikari/util/UtilityElf.java
Expand Up @@ -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;
}
}
}

0 comments on commit 2f3a107

Please sign in to comment.