Example usage for java.util.concurrent ScheduledThreadPoolExecutor allowCoreThreadTimeOut

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor allowCoreThreadTimeOut

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor allowCoreThreadTimeOut.

Prototype

public void allowCoreThreadTimeOut(boolean value) 

Source Link

Document

Sets the policy governing whether core threads may time out and terminate if no tasks arrive within the keep-alive time, being replaced if needed when new tasks arrive.

Usage

From source file:com.amazonaws.http.HttpRequestTimer.java

private static ScheduledThreadPoolExecutor createExecutor() {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5);
    safeSetRemoveOnCancel(executor);/*from w w w  .  ja va2 s .  c  o  m*/
    executor.setKeepAliveTime(5, TimeUnit.SECONDS);
    executor.allowCoreThreadTimeOut(true);
    return executor;
}

From source file:io.bitsquare.common.util.Utilities.java

public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name, int corePoolSize,
        int maximumPoolSize, long keepAliveTimeInSec) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true)
            .setPriority(Thread.MIN_PRIORITY).build();
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
    executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS);
    executor.allowCoreThreadTimeOut(true);
    executor.setMaximumPoolSize(maximumPoolSize);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setRejectedExecutionHandler((r, e) -> {
        log.debug("RejectedExecutionHandler called");
    });//ww  w  .j a  va  2  s .c  o  m
    return executor;
}

From source file:io.joynr.messaging.MessagingModule.java

@Provides
@Named(MessageScheduler.SCHEDULEDTHREADPOOL)
ScheduledExecutorService provideMessageSchedulerThreadPoolExecutor(
        @Named(ConfigurableMessagingSettings.PROPERTY_MESSAGING_MAXIMUM_PARALLEL_SENDS) int maximumParallelSends) {
    ThreadFactory schedulerNamedThreadFactory = new ThreadFactoryBuilder()
            .setNameFormat("joynr.MessageScheduler-scheduler-%d").build();
    ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(maximumParallelSends,
            schedulerNamedThreadFactory);
    scheduler.setKeepAliveTime(100, TimeUnit.SECONDS);
    scheduler.allowCoreThreadTimeOut(true);
    return scheduler;
}

From source file:org.mule.transport.AbstractConnector.java

protected ScheduledExecutorService createScheduler() {
    // Use connector's classloader so that other temporary classloaders
    // aren't used when things are started lazily or from elsewhere.
    ThreadFactory threadFactory = new NamedThreadFactory(this.getName() + ".scheduler",
            muleContext.getExecutionClassLoader());
    ScheduledThreadPoolExecutor newExecutor = new ScheduledThreadPoolExecutor(4, threadFactory);
    newExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    newExecutor.setKeepAliveTime(this.getReceiverThreadingProfile().getThreadTTL(), TimeUnit.MILLISECONDS);
    newExecutor.allowCoreThreadTimeOut(true);
    return newExecutor;
}