Search in sources :

Example 76 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project HikariCP by brettwooldridge.

the class HikariPool method initializeHouseKeepingExecutorService.

/**
 * Create/initialize the Housekeeping service {@link ScheduledExecutorService}.  If the user specified an Executor
 * to be used in the {@link HikariConfig}, then we use that.  If no Executor was specified (typical), then create
 * an Executor and configure it.
 *
 * @return either the user specified {@link ScheduledExecutorService}, or the one we created
 */
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)

Example 77 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project elasticsearch-jdbc by jprante.

the class JDBCImporter method schedule.

private List<Future> schedule(Settings settings) {
    List<Future> futures = new LinkedList<>();
    if (threadPoolExecutor != null) {
        logger.info("already scheduled");
        return futures;
    }
    String[] schedule = settings.getAsArray("schedule");
    Long seconds = settings.getAsTime("interval", TimeValue.timeValueSeconds(0)).seconds();
    if (schedule != null && schedule.length > 0) {
        Thread thread = new Thread(this);
        CronThreadPoolExecutor cronThreadPoolExecutor = new CronThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
        for (String cron : schedule) {
            futures.add(cronThreadPoolExecutor.schedule(thread, new CronExpression(cron)));
        }
        this.threadPoolExecutor = cronThreadPoolExecutor;
        logger.info("scheduled with cron expressions {}", Arrays.asList(schedule));
    } else if (seconds > 0L) {
        Thread thread = new Thread(this);
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
        futures.add(scheduledThreadPoolExecutor.scheduleAtFixedRate(thread, 0L, seconds, TimeUnit.SECONDS));
        this.threadPoolExecutor = scheduledThreadPoolExecutor;
        logger.info("scheduled at fixed rate of {} seconds", seconds);
    }
    return futures;
}
Also used : CronThreadPoolExecutor(org.xbib.elasticsearch.common.cron.CronThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Future(java.util.concurrent.Future) CronExpression(org.xbib.elasticsearch.common.cron.CronExpression) LinkedList(java.util.LinkedList)

Example 78 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project jersey by jersey.

the class RxListenableFutureTest method setUp.

@Before
public void setUp() throws Exception {
    client = ClientBuilder.newClient().register(TerminalClientRequestFilter.class);
    executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("jersey-rx-client-test-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
}
Also used : JerseyProcessingUncaughtExceptionHandler(org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadFactoryBuilder(org.glassfish.jersey.internal.guava.ThreadFactoryBuilder) Before(org.junit.Before)

Example 79 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project jersey by jersey.

the class RxFlowableTest method setUp.

@Before
public void setUp() throws Exception {
    client = ClientBuilder.newClient().register(TerminalClientRequestFilter.class);
    client.register(RxFlowableInvokerProvider.class);
    executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("jersey-rx-client-test-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
}
Also used : JerseyProcessingUncaughtExceptionHandler(org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadFactoryBuilder(org.glassfish.jersey.internal.guava.ThreadFactoryBuilder) Before(org.junit.Before)

Example 80 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project elasticsearch-jdbc by jprante.

the class StandardContext method setSettings.

@Override
public StandardContext setSettings(Settings settings) {
    this.settings = settings;
    if (settings.getAsBoolean("metrics.enabled", false) && futures.isEmpty()) {
        Thread thread = new MetricsThread();
        ScheduledThreadPoolExecutor scheduledthreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        futures.add(scheduledthreadPoolExecutor.scheduleAtFixedRate(thread, 0L, settings.getAsTime("metrics.interval", TimeValue.timeValueSeconds(30)).seconds(), TimeUnit.SECONDS));
        logger.info("metrics thread started");
    }
    return this;
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)154 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)31 Test (org.junit.Test)26 ExecutorService (java.util.concurrent.ExecutorService)24 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)22 ThreadFactory (java.util.concurrent.ThreadFactory)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)8 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 File (java.io.File)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 IOException (java.io.IOException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7