/* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain. Use, modify, and * redistribute this code in any way without acknowledgement. */ package java.util.concurrent; import java.util.List; /** * An executor that provides methods to manage termination. An * ExecutorService can be shut down, which will cause it to * stop accepting new tasks. After being shut down, the executor will * eventually terminate, at which point no tasks are actively * executing, no tasks are awaiting execution, and no new tasks can be * submitted. * *

The Executors class provides factory methods for the * executor services provided in java.util.concurrent. * * @since 1.5 * @see Executors * * @spec JSR-166 * @revised $Date: 2003/05/27 18:15:49 $ * @editor $Author: jozart $ */ public interface ExecutorService extends Executor { /** * Initiates an orderly shutdown in which previously submitted tasks * are executed, but no new tasks will be accepted. * */ void shutdown(); /** * Attempts to stop all actively executing tasks, halts the * processing of waiting tasks, and returns a list of the tasks that were * awaiting execution. * *

There are no guarantees beyond best-effort attempts to stop * processing actively executing tasks. For example, typical * implementations will cancel via {@link Thread#interrupt}, so if any * tasks mask or fail to respond to interrupts, they may never terminate. * * @return list of tasks that never commenced execution */ List shutdownNow(); /** * Returns true if this executor has been shut down. * * @return true if this executor has been shut down */ boolean isShutdown(); /** * Returns true if all tasks have completed following shut down. * Note that isTerminated is never true unless * either shutdown or shutdownNow was called first. * * @return true if all tasks have completed following shut down */ boolean isTerminated(); /** * Blocks until all tasks have completed execution after a shutdown * request, or the timeout occurs, or the current thread is * interrupted, whichever happens first. * * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @return true if this executor terminated and false * if the timeout elapsed before termination * @throws InterruptedException if interrupted while waiting */ boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException; }