T
- The result object type returned by this futurepublic class ExecuteOnGetFutureTask<T> extends ListenableFutureTask<T>
get()
IF it has not already started. It is still expected that this future will be
provided to an executor, but if that executor has been unable to start execution by the time
get()
is requested, execution will start on the get()
thread.
This can make sense if for example you need to have the result of a given future before you can
go forward with additional work. That way if the thread pool is too busy with other things, we
can try to get the result for this work unit as fast as possible (once we are ready for it).
If execution starts on the get()
call, once the task is started in the thread pool, it
will return immediately (WITHOUT invoking the task contained in the future).
This does come with some details to be aware of. Execution may only occur on the
get()
request. Requesting FutureTask.get(long, java.util.concurrent.TimeUnit)
will NOT
cause execution to start (as we can not ensure a timeout will be respected). In addition this
can not work with recurring tasks.
ListenableFuture.ListenerOptimizationStrategy
Constructor and Description |
---|
ExecuteOnGetFutureTask(java.util.concurrent.Callable<T> task)
Constructs a runnable future with a callable work unit.
|
ExecuteOnGetFutureTask(java.lang.Runnable task)
Constructs a runnable future with a runnable work unit.
|
ExecuteOnGetFutureTask(java.lang.Runnable task,
T result)
Constructs a runnable future with a runnable work unit.
|
Modifier and Type | Method and Description |
---|---|
T |
get() |
void |
run() |
addListener, getContainedCallable
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCallback, addCallback, addCallback, addListener, addListener, flatMap, flatMap, flatMap, map, map, map
public ExecuteOnGetFutureTask(java.lang.Runnable task)
task
- runnable to be runpublic ExecuteOnGetFutureTask(java.lang.Runnable task, T result)
task
- runnable to be runresult
- result to be provide after run has completedpublic ExecuteOnGetFutureTask(java.util.concurrent.Callable<T> task)
task
- callable to be runpublic void run()
run
in interface java.lang.Runnable
run
in interface java.util.concurrent.RunnableFuture<T>
run
in class ListenableFutureTask<T>