shut Down ExecutorService Synchronously - Java java.util.concurrent

Java examples for java.util.concurrent:ExecutorService

Description

shut Down ExecutorService Synchronously

Demo Code


//package com.java2s;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void shutDownSynchronously(ExecutorService executorService) {
        if (executorService != null) {
            executorService.shutdown();/* ww  w  .  j a va 2  s . c  om*/
            while (!executorService.isTerminated()) {
                try {
                    executorService.awaitTermination(1, TimeUnit.MINUTES);
                } catch (InterruptedException e) {
                    // Do not return on interrupts, but wait until all submitted tasks are completed.
                }
            }
        }
    }
}

Related Tutorials