java.util.concurrent
Interface ExecutorService

All Superinterfaces:
Executor
All Known Implementing Classes:
ScheduledExecutor, ThreadPoolExecutor

public interface ExecutorService
extends Executor

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 this package.

Since:
1.5

Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
          Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
 boolean isShutdown()
          Returns true if this executor has been shut down.
 boolean isTerminated()
          Returns true if all tasks have completed following shut down.
 void shutdown()
          Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
 List shutdownNow()
          Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
 
Methods inherited from interface java.util.concurrent.Executor
execute
 

Method Detail

shutdown

void shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.


shutdownNow

List shutdownNow()
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 Thread.interrupt(), so if any tasks mask or fail to respond to interrupts, they may never terminate.

Returns:
list of tasks that never commenced execution

isShutdown

boolean isShutdown()
Returns true if this executor has been shut down.

Returns:
true if this executor has been shut down

isTerminated

boolean isTerminated()
Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:
true if all tasks have completed following shut down

awaitTermination

boolean awaitTermination(long timeout,
                         TimeUnit unit)
                         throws InterruptedException
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if this executor terminated and false if the timeout elapsed before termination
Throws:
InterruptedException - if interrupted while waiting