@Beta @CanIgnoreReturnValue @GwtIncompatible public abstract class AbstractListeningExecutorService extends AbstractExecutorService implements ListeningExecutorService
ListeningExecutorService
implementation that creates ListenableFuture
instances for each Runnable
and Callable
submitted to it. These tasks are run
with the abstract execute(Runnable)
method.
In addition to Executor.execute(java.lang.Runnable)
, subclasses must implement all methods related to shutdown and
termination.
Constructor and Description |
---|
AbstractListeningExecutorService() |
Modifier and Type | Method and Description |
---|---|
protected <T> RunnableFuture<T> |
newTaskFor(Callable<T> callable)
Returns a
RunnableFuture for the given callable task. |
protected <T> RunnableFuture<T> |
newTaskFor(Runnable runnable,
T value)
Returns a
RunnableFuture for the given runnable and default
value. |
<T> ListenableFuture<T> |
submit(Callable<T> task)
Submits a value-returning task for execution and returns a
Future representing the pending results of the task.
|
ListenableFuture<?> |
submit(Runnable task)
Submits a Runnable task for execution and returns a Future
representing that task.
|
<T> ListenableFuture<T> |
submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future
representing that task.
|
invokeAll, invokeAll, invokeAny, invokeAny
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
invokeAll, invokeAll
awaitTermination, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow
public AbstractListeningExecutorService()
protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
java.util.concurrent.AbstractExecutorService
RunnableFuture
for the given runnable and default
value.newTaskFor
in class AbstractExecutorService
T
- the type of the given valuerunnable
- the runnable task being wrappedvalue
- the default value for the returned futureRunnableFuture
which, when run, will run the
underlying runnable and which, as a Future
, will yield
the given value as its result and provide for cancellation of
the underlying taskListenableFutureTask
since 14.0)protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
java.util.concurrent.AbstractExecutorService
RunnableFuture
for the given callable task.newTaskFor
in class AbstractExecutorService
T
- the type of the callable's resultcallable
- the callable task being wrappedRunnableFuture
which, when run, will call the
underlying callable and which, as a Future
, will yield
the callable's result as its result and provide for
cancellation of the underlying taskListenableFutureTask
since 14.0)public ListenableFuture<?> submit(Runnable task)
java.util.concurrent.ExecutorService
get
method will
return null
upon successful completion.submit
in interface ListeningExecutorService
submit
in interface ExecutorService
submit
in class AbstractExecutorService
task
- the task to submitpublic <T> ListenableFuture<T> submit(Runnable task, @NullableDecl T result)
java.util.concurrent.ExecutorService
get
method will
return the given result upon successful completion.submit
in interface ListeningExecutorService
submit
in interface ExecutorService
submit
in class AbstractExecutorService
T
- the type of the resulttask
- the task to submitresult
- the result to returnpublic <T> ListenableFuture<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 ListeningExecutorService
submit
in interface ExecutorService
submit
in class AbstractExecutorService
T
- the type of the task's resulttask
- the task to submitCopyright © 2010–2019. All rights reserved.