|
||||||||||
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)
Adds a listener and executor to the ListenableFuture. |
protected void |
done()
|
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
Adds a listener and executor to the ListenableFuture.
The listener will be passed
to the executor for execution when the Future
's computation is
complete.
There is no guaranteed ordering of execution of listeners, they may get called in the order they were added and they may get called out of order, but any listener added through this method is guaranteed to be called once the computation is complete.
addListener
in interface ListenableFuture<V>
listener
- the listener to run when the computation is complete.exec
- the executor to run the listener in.protected void done()
done
in class FutureTask<V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |