Java Duration Calculate awaitTermination(ExecutorService service, Logger logger, Duration timeout, String technique)

Here you can find the source of awaitTermination(ExecutorService service, Logger logger, Duration timeout, String technique)

Description

Await termination of the given ExecutorService .

License

Open Source License

Return

true if the executor terminated in time, false if it timed out

Declaration

public static boolean awaitTermination(ExecutorService service, Logger logger, Duration timeout,
        String technique) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.Duration;

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

public class Main {
    /**/* w w w  .j  a va 2  s . co  m*/
     * Await termination of the given {@link ExecutorService}. If it does not terminate within the
     * given time, log a severe error to the given logger, mentioning that the given technique was
     * used to try and shut it down.
     *
     * @return true if the executor terminated in time, false if it timed out
     */
    public static boolean awaitTermination(ExecutorService service, Logger logger, Duration timeout,
            String technique) {
        try {
            service.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS);
            return true;
        } catch (InterruptedException e) {
            logger.severe(technique + " shutdown of " + service + " did not complete within " + timeout);
            return false;
        }
    }
}

Related

  1. adjustServerTimeout(Duration clientTimeout)
  2. calculateDuration(Duration minimum, Duration maximum, Long iteration)
  3. daysRoundingUp(Duration duration)
  4. delayedFuture(Duration delay, ScheduledExecutorService executorService)
  5. durationFromNow(TemporalAmount duration)