@Beta public abstract class AbstractListeningExecutorService extends AbstractExecutorService implements ListeningExecutorService
ListeningExecutorService
implementation that creates
ListenableFutureTask
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> ListenableFutureTask<T> |
newTaskFor(Callable<T> callable)
Returns a RunnableFuture for the given callable task.
|
protected <T> ListenableFutureTask<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> ListenableFutureTask<T> newTaskFor(Runnable runnable, T value)
java.util.concurrent.AbstractExecutorService
newTaskFor
in class AbstractExecutorService
runnable
- the runnable task being wrappedvalue
- the default value for the returned futureprotected final <T> ListenableFutureTask<T> newTaskFor(Callable<T> callable)
java.util.concurrent.AbstractExecutorService
newTaskFor
in class AbstractExecutorService
callable
- the callable task being wrappedpublic ListenableFuture<?> submit(Runnable task)
java.util.concurrent.ExecutorService
submit
in interface ListeningExecutorService
submit
in interface ExecutorService
submit
in class AbstractExecutorService
task
- the task to submitpublic <T> ListenableFuture<T> submit(Runnable task, @Nullable T result)
java.util.concurrent.ExecutorService
submit
in interface ListeningExecutorService
submit
in interface ExecutorService
submit
in class AbstractExecutorService
task
- the task to submitresult
- the result to returnpublic <T> ListenableFuture<T> submit(Callable<T> task)
java.util.concurrent.ExecutorService
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
task
- the task to submitCopyright © 2010-2014. All Rights Reserved.