|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.concurrent.FutureTask<V> com.google.common.util.concurrent.ListenableFutureTask<V>
@Beta public class ListenableFutureTask<V>
A FutureTask
that also implements the ListenableFuture
interface. Subclasses must make sure to call super.done()
if they
also override the done()
method, otherwise the listeners will not
be called.
Constructor Summary | |
---|---|
ListenableFutureTask(Callable<V> callable)
Creates a ListenableFutureTask that will upon running, execute the
given Callable . |
|
ListenableFutureTask(Runnable runnable,
V result)
Creates a ListenableFutureTask that will upon running, execute the
given Runnable , and arrange that get will return the
given result on successful completion. |
Method Summary | |
---|---|
void |
addListener(Runnable listener,
Executor exec)
Registers a listener to be run on the given executor. |
protected void |
done()
Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). |
Methods inherited from class java.util.concurrent.FutureTask |
---|
cancel, get, get, isCancelled, isDone, run, runAndReset, set, setException |
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.Future |
---|
cancel, get, get, isCancelled, isDone |
Constructor Detail |
---|
public ListenableFutureTask(Callable<V> callable)
ListenableFutureTask
that will upon running, execute the
given Callable
.
callable
- the callable task
NullPointerException
- if callable is nullpublic ListenableFutureTask(Runnable runnable, V result)
ListenableFutureTask
that will upon running, execute the
given Runnable
, and arrange that get
will return the
given result on successful completion.
runnable
- the runnable taskresult
- the result to return on successful completion. If
you don't need a particular result, consider using
constructions of the form:
ListenableFuture<?> f =
new ListenableFutureTask<Object>(runnable, null)
NullPointerException
- if runnable is nullMethod Detail |
---|
public void addListener(Runnable listener, Executor exec)
ListenableFuture
Future
's
computation is complete or, if the computation
is already complete, immediately.
There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete.
Listeners cannot throw checked exceptions and should not throw RuntimeException
unless their executors are prepared to handle it.
Listeners that will execute in MoreExecutors.sameThreadExecutor()
should take special care, since they may run during the call to addListener
or during the call that sets the future's value.
addListener
in interface ListenableFuture<V>
listener
- the listener to run when the computation is completeexec
- the executor to run the listener inprotected void done()
java.util.concurrent.FutureTask
done
in class FutureTask<V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |