Example usage for java.util.concurrent ExecutorService shutdownNow

List of usage examples for java.util.concurrent ExecutorService shutdownNow

Introduction

In this page you can find the example usage for java.util.concurrent ExecutorService shutdownNow.

Prototype

List<Runnable> shutdownNow();

Source Link

Document

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

Usage

From source file:com.mobius.software.mqtt.performance.runner.ScenarioRunner.java

public void start() throws InterruptedException {
    List<RequestWorker> workers = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(requests.size());
    for (ScenarioRequest request : requests)
        workers.add(new RequestWorker(request, latch));

    ExecutorService service = Executors.newFixedThreadPool(workers.size());
    for (RequestWorker worker : workers)
        service.submit(worker);/*from   w ww  . j a v a  2s  . co  m*/
    latch.await();

    service.shutdownNow();
}

From source file:br.com.uol.runas.service.JUnitService.java

public JUnitServiceResponse runTests(String path, final String[] suites) throws Exception {
    try (final JarClassLoader classLoader = new JarClassLoader(path, classLoaderGC)) {
        final ThreadFactory threadFactory = new ThreadFactoryImpl(classLoader);

        final ExecutorService service = Executors.newSingleThreadExecutor(threadFactory);

        try {/*ww  w.  j  a v a2s. c o m*/
            return service.submit(new JUnitTask(suites)).get();
        } finally {
            service.shutdownNow();
        }
    }
}

From source file:eu.artofcoding.beetlejuice.spring.SpringContextHelper.java

/**
 * http://forum.springsource.org/showthread.php?125695-Orderly-shutdown-how-to-know-when-downstream-executor-is-idle
 * @param shutdownForced//w ww  .j av  a  2s. co m
 */
public void stopSchedulers(boolean shutdownForced) {
    logger.info(String.format("Stopping schedulers %s", shutdownForced ? "(force)" : ""));
    List<ExecutorService> executorServices = new ArrayList<ExecutorService>();
    Map<String, ThreadPoolTaskScheduler> schedulers = applicationContext
            .getBeansOfType(ThreadPoolTaskScheduler.class);
    for (Map.Entry<String, ThreadPoolTaskScheduler> entry : schedulers.entrySet()) {
        ThreadPoolTaskScheduler scheduler = entry.getValue();
        logger.info(String.format("Stopping scheduler %s", scheduler.getThreadNamePrefix()));
        ExecutorService executorService = scheduler.getScheduledExecutor();
        executorServices.add(executorService);
        if (shutdownForced) {
            executorService.shutdownNow();
        } else {
            executorService.shutdown();
        }
    }
    waitForExecutors(executorServices);
    logger.info("Stopped schedulers");
}

From source file:org.hyperic.hq.agent.server.CommandListener.java

/**
 * Shut down the command listener.//from w  w  w  .  ja  v  a2  s. c  o  m
 *
 * @throws AgentRunningException indicating the listener was not listening
 *                               when 'die' was requested.
 */
void die() throws AgentRunningException {
    shutdown.set(true);
    for (final Entry<String, ExecutorService> entry : threadPools.entrySet()) {
        final ExecutorService pool = entry.getValue();
        pool.shutdownNow();
        log.info("Shut down executor service for CommandListener " + entry.getKey());
    }
}

From source file:org.geoserver.wms.WMSLifecycleHandler.java

/**
 * Suddenly shuts down the Animator Executor Service
 *//*from  w  w  w.  jav  a 2s . co m*/
private void shutdownAnimatorExecutorService() {
    final ExecutorService animatorExecutorService = this.wmsConfig.getAnimatorExecutorService();
    if (animatorExecutorService != null && !animatorExecutorService.isShutdown()) {
        animatorExecutorService.shutdownNow();
    }
}

From source file:org.apache.tajo.storage.HashShuffleAppenderManager.java

public void shutdown() {
    for (ExecutorService service : executors.values()) {
        service.shutdownNow();
    }
}

From source file:com.adaptris.core.lifecycle.FilteredSharedComponentStart.java

private void shutdownExecutors() {
    for (ExecutorService es : connectionStarters.values()) {
        es.shutdownNow();
    }
}

From source file:Main.java

public static boolean stop(ExecutorService executorService, int waitBeforeTerminateSecs, Logger logger)
/*     */ {//from  w w  w.j a  va  2s  .co m
    /*  53 */int waitMillis = Math.max(1000, 1000 * waitBeforeTerminateSecs);
    /*     */
    /*     */
    /*  56 */executorService.shutdown();
    /*     */
    /*     */
    /*  59 */boolean stopped = false;
    /*  60 */while ((waitMillis > 0) && (!stopped)) {
        /*  61 */long startMillis = System.currentTimeMillis();
        /*     */try {
            /*  63 */logger.debug("Waiting for thread pool to stop");
            /*  64 */stopped = executorService.awaitTermination(waitMillis, TimeUnit.MILLISECONDS);
            /*     */} catch (InterruptedException e) {
            /*  66 */logger.debug("Thread was interrupted while it was waiting for thread pool to stop", e);
            /*  67 */Thread.currentThread().interrupt();
            /*  68 */break;
            /*     */}
        /*  70 */waitMillis = (int) (waitMillis - (System.currentTimeMillis() - startMillis));
        /*     */}
    /*     */
    /*  73 */if (!executorService.isTerminated()) {
        /*  74 */logger.warn("Thread pool will be forcibly stopped now if it has not already stopped");
        /*  75 */executorService.shutdownNow();
        /*     */try {
            /*  77 */stopped = executorService.awaitTermination(waitBeforeTerminateSecs, TimeUnit.SECONDS);
            /*     */}
        /*     */catch (InterruptedException e) {
        }
        /*     */
        /*  81 */if (!executorService.isTerminated()) {
            /*  82 */logger.warn("Could not shutdown thread pool in [{}] seconds",
                    Integer.valueOf(waitBeforeTerminateSecs));
            /*     */}
        /*     */}
    /*     */
    /*  86 */return stopped;
    /*     */}

From source file:com.ejisto.modules.executor.TaskManager.java

private void shutdownExecutorService(ExecutorService service) {
    try {//from w ww.  j ava2 s. c o  m
        service.shutdown();
        if (!service.awaitTermination(5L, SECONDS)) {
            service.shutdownNow();
        }
    } catch (InterruptedException e) {
        service.shutdownNow();
        Thread.currentThread().interrupt();
    }
}

From source file:com.mgmtp.jfunk.core.JFunk.java

private void shutDownExecutorService(final ExecutorService execService) {
    try {/*from ww  w  . jav a  2s.c o m*/
        execService.shutdownNow();
        execService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException ex) {
        LOG.error("Script execution was interrupted.", ex);
    }
}