T
- The result object type returned by this futurepublic class ListenableFutureTask<T> extends java.util.concurrent.FutureTask<T> implements ListenableRunnableFuture<T>, CallableContainer<T>
Executor
, and then return this future.ListenableFuture.ListenerOptimizationStrategy
Constructor and Description |
---|
ListenableFutureTask(boolean recurring,
java.util.concurrent.Callable<T> task)
Constructs a runnable future with a callable work unit.
|
ListenableFutureTask(boolean recurring,
java.util.concurrent.Callable<T> task,
java.util.concurrent.Executor executingExecutor)
Constructs a runnable future with a callable work unit.
|
ListenableFutureTask(boolean recurring,
java.lang.Runnable task)
Constructs a runnable future with a runnable work unit.
|
ListenableFutureTask(boolean recurring,
java.lang.Runnable task,
java.util.concurrent.Executor executingExecutor)
Deprecated.
|
ListenableFutureTask(boolean recurring,
java.lang.Runnable task,
T result)
Constructs a runnable future with a runnable work unit.
|
ListenableFutureTask(boolean recurring,
java.lang.Runnable task,
T result,
java.util.concurrent.Executor executingExecutor)
Constructs a runnable future with a runnable work unit.
|
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.Callable<T> |
getContainedCallable()
Call to get the contained callable held within the wrapper.
|
java.lang.StackTraceElement[] |
getRunningStackTrace()
A best effort to return the stack trace for for the executing thread of either this future,
or a future which this depends on through the use of
ListenableFuture.map(Function) or similar
functions. |
ListenableFuture<T> |
listener(java.lang.Runnable listener,
java.util.concurrent.Executor executor,
ListenableFuture.ListenerOptimizationStrategy optimize)
Add a listener to be called once the future has completed.
|
void |
run() |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCallback, addCallback, addCallback, addListener, addListener, addListener, callback, callback, callback, failureCallback, failureCallback, failureCallback, flatMap, flatMap, flatMap, flatMap, flatMapFailure, flatMapFailure, flatMapFailure, listener, listener, map, map, map, mapFailure, mapFailure, mapFailure, resultCallback, resultCallback, resultCallback, throwMap, throwMap, throwMap
public ListenableFutureTask(boolean recurring, java.lang.Runnable task)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- runnable to be runpublic ListenableFutureTask(boolean recurring, java.lang.Runnable task, T result)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- runnable to be runresult
- result to be provide after run has completedpublic ListenableFutureTask(boolean recurring, java.util.concurrent.Callable<T> task)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- callable to be run@Deprecated public ListenableFutureTask(boolean recurring, java.lang.Runnable task, java.util.concurrent.Executor executingExecutor)
ListenableFutureTask(boolean, Runnable, Object, Executor)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- runnable to be runexecutingExecutor
- Executor task will be run on for possible listener optimization, or null
public ListenableFutureTask(boolean recurring, java.lang.Runnable task, T result, java.util.concurrent.Executor executingExecutor)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- runnable to be runresult
- result to be provide after run has completedexecutingExecutor
- Executor task will be run on for possible listener optimization, or null
public ListenableFutureTask(boolean recurring, java.util.concurrent.Callable<T> task, java.util.concurrent.Executor executingExecutor)
recurring
- boolean to indicate if this task can run multiple times, and thus must be reset after each runtask
- callable to be runexecutingExecutor
- Executor task will be run on for possible listener optimization, or null
public void run()
public ListenableFuture<T> listener(java.lang.Runnable listener, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
ListenableFuture
If the provided Executor
is null, the listener will execute on the thread which
computed the original future (once it is done). If the future has already completed, the
listener will execute immediately on the thread which is adding the listener.
Caution should be used when choosing to optimize the listener execution. If the listener is
complex, or wanting to be run concurrent, this optimization could prevent that. In addition
it will prevent other listeners from potentially being invoked until it completes. However
if the listener is small / fast, this can provide significant performance gains. It should
also be known that not all ListenableFuture
implementations may be able to do such an
optimization. Please see ListenableFuture.ListenerOptimizationStrategy
javadocs for more specific
details of what optimizations are available.
listener
in interface ListenableFuture<T>
listener
- the listener to run when the computation is completeexecutor
- Executor
the listener should be ran on, or null
optimize
- true
to avoid listener queuing for execution if already on the desired poolthis
instance to add more listeners or other functional operationspublic java.util.concurrent.Callable<T> getContainedCallable()
CallableContainer
getContainedCallable
in interface CallableContainer<T>
null
if none is containedpublic java.lang.StackTraceElement[] getRunningStackTrace()
ListenableFuture
ListenableFuture.map(Function)
or similar
functions. If there is no thread executing the future yet, or the future has already
completed, then this will return null
.
This is done without locking (though generating a stack trace still requires a JVM safe point), so the resulting stack trace is NOT guaranteed to be accurate. In most cases (particularly when blocking) this should be accurate though.
getRunningStackTrace
in interface ListenableFuture<T>
null
if unavailable