Example usage for java.util.concurrent ScheduledThreadPoolExecutor setRejectedExecutionHandler

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

Introduction

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

Prototype

public void setRejectedExecutionHandler(RejectedExecutionHandler handler) 

Source Link

Document

Sets a new handler for unexecutable tasks.

Usage

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");
    });/*from  w  w w.j a v a 2s.  c om*/
    return executor;
}