Class AbstractListeningExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- com.google.common.util.concurrent.AbstractListeningExecutorService
-
- All Implemented Interfaces:
ListeningExecutorService
,Executor
,ExecutorService
@Beta @CanIgnoreReturnValue @GwtIncompatible public abstract class AbstractListeningExecutorService extends AbstractExecutorService implements ListeningExecutorService
AbstractListeningExecutorService
implementation that createsListenableFuture
instances for eachRunnable
andCallable
submitted to it. These tasks are run with the abstractexecute(Runnable)
method.In addition to
Executor.execute(java.lang.Runnable)
, subclasses must implement all methods related to shutdown and termination.- Since:
- 14.0
- Author:
- Chris Povirk
-
-
Constructor Summary
Constructors Constructor Description AbstractListeningExecutorService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> RunnableFuture<T>
newTaskFor(Runnable runnable, T value)
Returns aRunnableFuture
for the given runnable and default value.protected <T> RunnableFuture<T>
newTaskFor(Callable<T> callable)
Returns aRunnableFuture
for the given callable 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.<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.-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow
-
Methods inherited from interface com.google.common.util.concurrent.ListeningExecutorService
invokeAll, invokeAll
-
-
-
-
Constructor Detail
-
AbstractListeningExecutorService
public AbstractListeningExecutorService()
-
-
Method Detail
-
newTaskFor
protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
Description copied from class:java.util.concurrent.AbstractExecutorService
Returns aRunnableFuture
for the given runnable and default value.- Overrides:
newTaskFor
in classAbstractExecutorService
- Type Parameters:
T
- the type of the given value- Parameters:
runnable
- the runnable task being wrappedvalue
- the default value for the returned future- Returns:
- a
RunnableFuture
which, when run, will run the underlying runnable and which, as aFuture
, will yield the given value as its result and provide for cancellation of the underlying task - Since:
- 19.0 (present with return type
ListenableFutureTask
since 14.0)
-
newTaskFor
protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
Description copied from class:java.util.concurrent.AbstractExecutorService
Returns aRunnableFuture
for the given callable task.- Overrides:
newTaskFor
in classAbstractExecutorService
- Type Parameters:
T
- the type of the callable's result- Parameters:
callable
- the callable task being wrapped- Returns:
- a
RunnableFuture
which, when run, will call the underlying callable and which, as aFuture
, will yield the callable's result as its result and provide for cancellation of the underlying task - Since:
- 19.0 (present with return type
ListenableFutureTask
since 14.0)
-
submit
public ListenableFuture<?> submit(Runnable task)
Description copied from interface:java.util.concurrent.ExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will returnnull
upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Parameters:
task
- the task to submit- Returns:
- a Future representing pending completion of the task
-
submit
public <T> ListenableFuture<T> submit(Runnable task, @NullableDecl T result)
Description copied from interface:java.util.concurrent.ExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will return the given result upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Type Parameters:
T
- the type of the result- Parameters:
task
- the task to submitresult
- the result to return- Returns:
- a Future representing pending completion of the task
-
submit
public <T> ListenableFuture<T> submit(Callable<T> task)
Description copied from interface:java.util.concurrent.ExecutorService
Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future'sget
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
toCallable
form so they can be submitted.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceListeningExecutorService
- Overrides:
submit
in classAbstractExecutorService
- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task to submit- Returns:
- a Future representing pending completion of the task
-
-