@GwtIncompatible public abstract class ForwardingExecutorService extends ForwardingObject implements ExecutorService
Modifier | Constructor and Description |
---|---|
protected |
ForwardingExecutorService()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected abstract ExecutorService |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
void |
execute(Runnable command)
Executes the given command at some time in the future.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks)
Executes the given tasks, returning a list of Futures holding
their status and results when all complete.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit)
Executes the given tasks, returning a list of Futures holding
their status and results
when all complete or the timeout expires, whichever happens first.
|
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks)
Executes the given tasks, returning the result
of one that has completed successfully (i.e., without throwing
an exception), if any do.
|
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit)
Executes the given tasks, returning the result
of one that has completed successfully (i.e., without throwing
an exception), if any do before the given timeout elapses.
|
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<Runnable> |
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.
|
<T> Future<T> |
submit(Callable<T> task)
Submits a value-returning task for execution and returns a
Future representing the pending results of the task.
|
Future<?> |
submit(Runnable task)
Submits a Runnable task for execution and returns a Future
representing that task.
|
<T> Future<T> |
submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future
representing that task.
|
toString
protected ForwardingExecutorService()
protected abstract ExecutorService delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply
the instance being decorated.delegate
in class ForwardingObject
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.ExecutorService
awaitTermination
in interface ExecutorService
timeout
- the maximum time to waitunit
- the time unit of the timeout argumenttrue
if this executor terminated and
false
if the timeout elapsed before terminationInterruptedException
- if interrupted while waitingpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
java.util.concurrent.ExecutorService
Future.isDone()
is true
for each
element of the returned list.
Note that a completed task could have
terminated either normally or by throwing an exception.
The results of this method are undefined if the given
collection is modified while this operation is in progress.invokeAll
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of tasksInterruptedException
- if interrupted while waiting, in
which case unfinished tasks are cancelledpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.ExecutorService
Future.isDone()
is true
for each
element of the returned list.
Upon return, tasks that have not completed are cancelled.
Note that a completed task could have
terminated either normally or by throwing an exception.
The results of this method are undefined if the given
collection is modified while this operation is in progress.invokeAll
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of taskstimeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if interrupted while waiting, in
which case unfinished tasks are cancelledpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
java.util.concurrent.ExecutorService
invokeAny
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of tasksInterruptedException
- if interrupted while waitingExecutionException
- if no task successfully completespublic <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
java.util.concurrent.ExecutorService
invokeAny
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of taskstimeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if interrupted while waitingExecutionException
- if no task successfully completesTimeoutException
- if the given timeout elapses before
any task successfully completespublic boolean isShutdown()
java.util.concurrent.ExecutorService
true
if this executor has been shut down.isShutdown
in interface ExecutorService
true
if this executor has been shut downpublic boolean isTerminated()
java.util.concurrent.ExecutorService
true
if all tasks have completed following shut down.
Note that isTerminated
is never true
unless
either shutdown
or shutdownNow
was called first.isTerminated
in interface ExecutorService
true
if all tasks have completed following shut downpublic void shutdown()
java.util.concurrent.ExecutorService
This method does not wait for previously submitted tasks to
complete execution. Use awaitTermination
to do that.
shutdown
in interface ExecutorService
public List<Runnable> shutdownNow()
java.util.concurrent.ExecutorService
This method does not wait for actively executing tasks to
terminate. Use awaitTermination
to
do that.
There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. For example, typical
implementations will cancel via Thread.interrupt()
, so any
task that fails to respond to interrupts may never terminate.
shutdownNow
in interface ExecutorService
public void execute(Runnable command)
java.util.concurrent.Executor
Executor
implementation.public <T> Future<T> submit(Callable<T> task)
java.util.concurrent.ExecutorService
get
method will return the task's result upon
successful completion.
If you would like to immediately block waiting
for a task, you can use constructions of the form
result = exec.submit(aCallable).get();
Note: The Executors
class includes a set of methods
that can convert some other common closure-like objects,
for example, PrivilegedAction
to
Callable
form so they can be submitted.
submit
in interface ExecutorService
T
- the type of the task's resulttask
- the task to submitpublic Future<?> submit(Runnable task)
java.util.concurrent.ExecutorService
get
method will
return null
upon successful completion.submit
in interface ExecutorService
task
- the task to submitpublic <T> Future<T> submit(Runnable task, T result)
java.util.concurrent.ExecutorService
get
method will
return the given result upon successful completion.submit
in interface ExecutorService
T
- the type of the resulttask
- the task to submitresult
- the result to returnCopyright © 2010–2017. All rights reserved.