Search in sources :

Example 1 with DefaultThreadFactory

use of com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory in project HikariCP by brettwooldridge.

the class PoolBase method createNetworkTimeoutExecutor.

private void createNetworkTimeoutExecutor(final DataSource dataSource, final String dsClassName, final String jdbcUrl) {
    // Temporary hack for MySQL issue: http://bugs.mysql.com/bug.php?id=75615
    if ((dsClassName != null && dsClassName.contains("Mysql")) || (jdbcUrl != null && jdbcUrl.contains("mysql")) || (dataSource != null && dataSource.getClass().getName().contains("Mysql"))) {
        netTimeoutExecutor = new SynchronousExecutor();
    } else {
        ThreadFactory threadFactory = config.getThreadFactory();
        threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory(poolName + " network timeout executor", true);
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(threadFactory);
        executor.setKeepAliveTime(15, SECONDS);
        executor.allowCoreThreadTimeOut(true);
        netTimeoutExecutor = executor;
    }
}
Also used : DefaultThreadFactory(com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory) DefaultThreadFactory(com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with DefaultThreadFactory

use of com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory in project HikariCP by brettwooldridge.

the class HikariPool method initializeHouseKeepingExecutorService.

private ScheduledExecutorService initializeHouseKeepingExecutorService() {
    if (config.getScheduledExecutor() == null) {
        final ThreadFactory threadFactory = Optional.ofNullable(config.getThreadFactory()).orElse(new DefaultThreadFactory(poolName + " housekeeper", true));
        final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
        executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        executor.setRemoveOnCancelPolicy(true);
        return executor;
    } else {
        return config.getScheduledExecutor();
    }
}
Also used : DefaultThreadFactory(com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory) DefaultThreadFactory(com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) UtilityElf.createThreadPoolExecutor(com.zaxxer.hikari.util.UtilityElf.createThreadPoolExecutor)

Aggregations

DefaultThreadFactory (com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 UtilityElf.createThreadPoolExecutor (com.zaxxer.hikari.util.UtilityElf.createThreadPoolExecutor)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1