Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.concurrent.ExecutorService;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;

public class Main {
    public static boolean stop(ExecutorService executorService, Logger logger)
    /*     */ {
        /*  40 */return stop(executorService, 10, logger);
        /*     */}

    public static boolean stop(ExecutorService executorService, int waitBeforeTerminateSecs, Logger logger)
    /*     */ {
        /*  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;
        /*     */}
}