Class ListenableFutureTask<T>
- java.lang.Object
- java.util.concurrent.FutureTask<T>
- org.springframework.util.concurrent.ListenableFutureTask<T>
- Type Parameters:
T
- the result type returned by this Future'sget
method
- All Implemented Interfaces:
Runnable
,Future<T>
,RunnableFuture<T>
,ListenableFuture<T>
public class ListenableFutureTask<T> extends FutureTask<T> implements ListenableFuture<T>
Extension ofFutureTask
that implementsListenableFuture
.- Since:
- 4.0
- Author:
- Arjen Poutsma
Constructor Summary
Constructors Constructor Description ListenableFutureTask(Runnable runnable, T result)
Create aListenableFutureTask
that will, upon running, execute the givenRunnable
, and arrange thatFutureTask.get()
will return the given result on successful completion.ListenableFutureTask(Callable<T> callable)
Create a newListenableFutureTask
that will, upon running, execute the givenCallable
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCallback(ListenableFutureCallback<? super T> callback)
Register the givenListenableFutureCallback
.void
addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
Java 8 lambda-friendly alternative with success and failure callbacks.CompletableFuture<T>
completable()
Expose thisListenableFuture
as a JDKCompletableFuture
.protected void
done()
Methods inherited from class java.util.concurrent.FutureTask
cancel, get, get, isCancelled, isDone, run, runAndReset, set, setException, toString
Constructor Detail
ListenableFutureTask
public ListenableFutureTask(Callable<T> callable)
Create a newListenableFutureTask
that will, upon running, execute the givenCallable
.- Parameters:
callable
- the callable task
ListenableFutureTask
public ListenableFutureTask(Runnable runnable, @Nullable T result)
Create aListenableFutureTask
that will, upon running, execute the givenRunnable
, and arrange thatFutureTask.get()
will return the given result on successful completion.- Parameters:
runnable
- the runnable taskresult
- the result to return on successful completion
Method Detail
addCallback
public void addCallback(ListenableFutureCallback<? super T> callback)
Description copied from interface:ListenableFuture
Register the givenListenableFutureCallback
.- Specified by:
addCallback
in interfaceListenableFuture<T>
- Parameters:
callback
- the callback to register
addCallback
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
Description copied from interface:ListenableFuture
Java 8 lambda-friendly alternative with success and failure callbacks.- Specified by:
addCallback
in interfaceListenableFuture<T>
- Parameters:
successCallback
- the success callbackfailureCallback
- the failure callback
completable
public CompletableFuture<T> completable()
Description copied from interface:ListenableFuture
Expose thisListenableFuture
as a JDKCompletableFuture
.- Specified by:
completable
in interfaceListenableFuture<T>
done
protected void done()
- Overrides:
done
in classFutureTask<T>