All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.growing.sdk.java.utils.ExecutorServiceUtils Maven / Gradle / Ivy

package io.growing.sdk.java.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

public class ExecutorServiceUtils {

    public static void awaitTerminationAfterShutdown(ExecutorService threadPool, long timeout) {
        awaitTerminationAfterShutdown(threadPool, timeout, TimeUnit.MILLISECONDS);
    }

    public static void awaitTerminationAfterShutdown(ExecutorService threadPool, long timeout, TimeUnit unit) {
        threadPool.shutdown();
        try {
            if (!threadPool.awaitTermination(timeout, unit)) {
                threadPool.shutdownNow();
            }
        } catch (InterruptedException ex) {
            threadPool.shutdownNow();
            Thread.currentThread().interrupt();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy