Example usage for com.google.common.util.concurrent ListeningScheduledExecutorService awaitTermination

List of usage examples for com.google.common.util.concurrent ListeningScheduledExecutorService awaitTermination

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ListeningScheduledExecutorService awaitTermination.

Prototype

boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;

Source Link

Document

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Usage

From source file:com.github.rinde.rinsim.core.model.time.RealtimeModel.java

void shutdownExecutor() {
    LOGGER.trace("Shutting down executor..");
    final ListeningScheduledExecutorService ex = realtimeState.executor;
    if (ex != null) {
        ex.shutdown();/*from w ww.  j  a  v  a  2s .  c o  m*/

        // in case the future could not be cancelled before, do it now
        final ListenableScheduledFuture<?> fut = realtimeState.schedulerFuture;
        if (fut != null && !fut.isDone()) {
            realtimeState.cancelTask();
        }

        try {
            ex.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        } catch (final InterruptedException e) {
            throw new IllegalStateException(e);
        }
        LOGGER.trace("Executor shutdown.");
    }
    verifyNotNull(affinityLock).release();
}