Example usage for java.util.concurrent ThreadPoolExecutor purge

List of usage examples for java.util.concurrent ThreadPoolExecutor purge

Introduction

In this page you can find the example usage for java.util.concurrent ThreadPoolExecutor purge.

Prototype

public void purge() 

Source Link

Document

Tries to remove from the work queue all Future tasks that have been cancelled.

Usage

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

public static void purge() {
    for (ThreadPoolExecutor threadPool : getThreadPools())
        threadPool.purge();
}

From source file:org.yccheok.jstock.engine.StockHistoryMonitor.java

public void stop() {
    ThreadPoolExecutor threadPoolExecutor = null;
    writerLock.lock();//from   w  ww  .  j  a  va2s. c  o  m
    try {
        threadPoolExecutor = ((ThreadPoolExecutor) pool);
        final int nThreads = threadPoolExecutor.getMaximumPoolSize();

        // Dangerous. Some users, do expect receive callback once they submit tasks into
        // monitor. However, if we are calling shutdownNow, user may not receive any
        // callback from those submitted tasks, which haven't started yet. Calling
        // shutdown() enables submitted tasks have chances to run once.
        //
        // threadPoolExecutor.shutdownNow();
        threadPoolExecutor.shutdown();
        threadPoolExecutor.purge();

        // pool is not valid any more. Discard it and re-create.
        pool = Executors.newFixedThreadPool(nThreads);
    } finally {
        writerLock.unlock();
    }

    // No unlock after awaitTermination, might cause deadlock.

    // How to wait for infinity?
    try {
        threadPoolExecutor.awaitTermination(100, TimeUnit.DAYS);
    } catch (InterruptedException exp) {
        log.error(null, exp);
    }
}