Example usage for java.util.concurrent ScheduledThreadPoolExecutor setKeepAliveTime

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

Introduction

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

Prototype

public void setKeepAliveTime(long time, TimeUnit unit) 

Source Link

Document

Sets the thread keep-alive time, which is the amount of time that threads may remain idle before being terminated.

Usage

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

private static ScheduledThreadPoolExecutor createExecutor() {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5);
    safeSetRemoveOnCancel(executor);//  w w  w  .java  2s. c  om
    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.jav a2s. com*/
    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.config.pool.DefaultThreadPoolFactory.java

protected ScheduledThreadPoolExecutor internalCreateScheduledPool(ThreadingProfile tp) {
    ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(
            Math.min(tp.getMaxThreadsIdle(), tp.getMaxThreadsActive()));
    scheduledThreadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
    scheduledThreadPoolExecutor.setKeepAliveTime(tp.getThreadTTL(), TimeUnit.MILLISECONDS);
    scheduledThreadPoolExecutor.setCorePoolSize(tp.getMaxThreadsIdle());
    scheduledThreadPoolExecutor.setMaximumPoolSize(tp.getMaxThreadsActive());
    return scheduledThreadPoolExecutor;
}

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;
}