Example usage for java.util.concurrent ExecutorService shutdown

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

Introduction

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

Prototype

void shutdown();

Source Link

Document

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

Usage

From source file:gov.ca.cwds.cals.service.ComplaintsService.java

@SuppressWarnings("squid:S2142") //Logging and informing client instead of shutdown
private void shutdownExecutionService(ExecutorService executorService) {
    executorService.shutdown();
    try {//from   w  w  w .  ja  va2 s  .com
        if (!executorService.awaitTermination(1, TimeUnit.MINUTES)) {
            executorService.shutdownNow();
        }
    } catch (InterruptedException e) {
        String message = "Can't properly shutdown complaints execution pool";
        LOGGER.warn(message, e);
        throw new ServiceException(message, e);
    }
}

From source file:org.apache.streams.elasticsearch.ElasticsearchPersistReader.java

protected void shutdownAndAwaitTermination(ExecutorService pool) {
    pool.shutdown(); // Disable new tasks from being submitted
    try {//from   www.  j  a va2  s  . c om
        // Wait a while for existing tasks to terminate
        if (!pool.awaitTermination(10, TimeUnit.SECONDS)) {
            pool.shutdownNow(); // Cancel currently executing tasks
            // Wait a while for tasks to respond to being cancelled
            if (!pool.awaitTermination(10, TimeUnit.SECONDS))
                LOGGER.error("Pool did not terminate");
        }
    } catch (InterruptedException ie) {
        // (Re-)Cancel if current thread also interrupted
        pool.shutdownNow();
        // Preserve interrupt status
        Thread.currentThread().interrupt();
    }
}

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

private void shutdownExecutorService(ExecutorService service) {
    try {/*  www. j a va  2  s . co  m*/
        service.shutdown();
        if (!service.awaitTermination(5L, SECONDS)) {
            service.shutdownNow();
        }
    } catch (InterruptedException e) {
        service.shutdownNow();
        Thread.currentThread().interrupt();
    }
}

From source file:com.janrain.backplane.config.BackplaneConfig.java

private void shutdownExecutor(String serviceName, ExecutorService executor) {
    try {//w  w w  .  j av  a2  s.  co m
        executor.shutdown();
        if (executor.awaitTermination(10, TimeUnit.SECONDS)) {
            logger.info(serviceName + " background thread shutdown properly");
        } else {
            executor.shutdownNow();
            if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                logger.error(serviceName + " background thread did not terminate");
            }
        }
    } catch (InterruptedException e) {
        logger.error(serviceName + " termination threw an exception", e);
        executor.shutdownNow();
        Thread.currentThread().interrupt();
    }
}

From source file:org.ops4j.orient.spring.tx.blueprints.OrientGraphTransactionTest.java

@Test
public void commitMultiThreaded() throws InterruptedException {

    ExecutorService executorService = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executorService.submit(new CommitTask());
    }//from   ww w.j av  a 2 s . com
    executorService.shutdown();
    executorService.awaitTermination(1000, TimeUnit.SECONDS);
}

From source file:org.ops4j.orient.spring.tx.document.DocumentDatabaseTransactionTest.java

@Test
public void commitMultiThreaded() throws InterruptedException {

    ExecutorService executorService = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executorService.submit(new CommitTask());
    }//from  w  w  w  .ja va 2s  . c o m
    executorService.shutdown();
    executorService.awaitTermination(1000, TimeUnit.SECONDS);

}

From source file:io.udvi.amqp.mq.transport.session.CAMQPSessionManager.java

private void shutdownThreadPool(ExecutorService threadPool) {
    threadPool.shutdown();
    try {// w w  w.j av  a2  s  . co  m
        threadPool.awaitTermination(300, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:com.janrain.backplane.server.config.Backplane1Config.java

@PreDestroy
private void cleanup() {
    for (ExecutorService executor : backgroundServices) {
        try {//from w w w .jav  a 2 s .com
            executor.shutdown();
            if (executor.awaitTermination(10, TimeUnit.SECONDS)) {
                logger.info("Background thread shutdown properly");
            } else {
                executor.shutdownNow();
                if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                    logger.error("Background thread did not terminate");
                }
            }
        } catch (InterruptedException e) {
            logger.error("error shutting down background service", e);
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
    }
}

From source file:edu.lternet.pasta.portal.HarvestReportServlet.java

private void executeHarvesterReportManager() {
    HarvestReportManager harvestReportManager = new HarvestReportManager(harvesterPath, harvesterReportTTL);
    ExecutorService executorService = Executors.newCachedThreadPool();
    executorService.execute(harvestReportManager);
    executorService.shutdown();
}

From source file:com.sangupta.httptools.DownloadUrlCommand.java

/**
 * Terminate the thread pool/* w  w w .  ja va  2s . c  om*/
 * 
 * @param pool
 *            the thread pool to terminate
 */
private void shutdownAndAwaitTermination(ExecutorService pool) {
    pool.shutdown(); // Disable new tasks from being submitted
    try {
        // Wait a while for existing tasks to terminate
        if (!pool.awaitTermination(1, TimeUnit.DAYS)) {
            pool.shutdownNow(); // Cancel currently executing tasks

            // Wait a while for tasks to respond to being cancelled
            if (!pool.awaitTermination(60, TimeUnit.SECONDS))
                System.err.println("Pool did not terminate");
        }
    } catch (InterruptedException ie) {
        // (Re-)Cancel if current thread also interrupted
        pool.shutdownNow();
        // Preserve interrupt status
        Thread.currentThread().interrupt();
    }
}