Example usage for java.util.concurrent ScheduledThreadPoolExecutor setContinueExistingPeriodicTasksAfterShutdownPolicy

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

Introduction

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

Prototype

public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value) 

Source Link

Document

Sets the policy on whether to continue executing existing periodic tasks even when this executor has been shutdown .

Usage

From source file:Main.java

/**
 * Have shutdown actually means shutdown. Tasks that need to complete should use
 * futures./*ww  w . jav  a  2s  .  c  om*/
 */
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name,
        UncaughtExceptionHandler handler, int poolSize, int stackSize) {
    // HACK: ScheduledThreadPoolExecutor won't let use the handler so
    // if we're using ExceptionHandlingRunnable then we'll be able to 
    // pick up the exceptions
    Thread.setDefaultUncaughtExceptionHandler(handler);

    ThreadFactory factory = getThreadFactory(name, handler);
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(poolSize, factory);
    executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    return executor;
}

From source file:com.l2jfree.util.concurrent.L2ThreadPool.java

public static void shutdown() {
    final long begin = System.currentTimeMillis();

    try {/* w ww.j  av a 2  s  .  co m*/
        System.out.println("L2ThreadPool: Shutting down.");
        System.out.println("\t... executing " + getTaskCount(_scheduledPools) + " scheduled tasks.");
        System.out.println("\t... executing " + getTaskCount(_instantPools) + " instant tasks.");
        System.out.println("\t... executing " + getTaskCount(_longRunningPools) + " long running tasks.");
    } catch (Throwable t) {
        t.printStackTrace();
    }

    try {
        for (ThreadPoolExecutor threadPool : getThreadPools()) {
            try {
                threadPool.shutdown();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }

    boolean success = false;
    try {
        success |= awaitTermination(5000);

        for (ScheduledThreadPoolExecutor scheduledPool : _scheduledPools) {
            scheduledPool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
            scheduledPool.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
        }

        success |= awaitTermination(10000);
    } catch (Throwable t) {
        t.printStackTrace();
    }

    try {
        System.out.println(
                "\t... success: " + success + " in " + (System.currentTimeMillis() - begin) + " msec.");
        System.out.println("\t... " + getTaskCount(_scheduledPools) + " scheduled tasks left.");
        System.out.println("\t... " + getTaskCount(_instantPools) + " instant tasks left.");
        System.out.println("\t... " + getTaskCount(_longRunningPools) + " long running tasks left.");

        if (TimeUnit.MINUTES.toMillis(30) < ManagementFactory.getRuntimeMXBean().getUptime())
            RunnableStatsManager.dumpClassStats(SortBy.TOTAL);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

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