类 AsyncResult<V>
- java.lang.Object
- org.springframework.scheduling.annotation.AsyncResult<V>
- 类型参数:
V- the value type
- 所有已实现的接口:
Future<V>,ListenableFuture<V>
public class AsyncResult<V> extends Object implements ListenableFuture<V>
A pass-throughFuturehandle that can be used for method signatures which are declared with aFuturereturn type for asynchronous execution.As of Spring 4.1, this class implements
ListenableFuture, not just plainFuture, along with the corresponding support in@Asyncprocessing.As of Spring 4.2, this class also supports passing execution exceptions back to the caller.
- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
Async,forValue(Object),forExecutionException(Throwable)
构造器概要
构造器 构造器 说明 AsyncResult(V value)Create a new AsyncResult holder.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddCallback(ListenableFutureCallback<? super V> callback)Register the givenListenableFutureCallback.voidaddCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)Java 8 lambda-friendly alternative with success and failure callbacks.booleancancel(boolean mayInterruptIfRunning)CompletableFuture<V>completable()Expose thisListenableFutureas a JDKCompletableFuture.static <V> ListenableFuture<V>forExecutionException(Throwable ex)Create a new async result which exposes the given exception as anExecutionExceptionfromFuture.get().static <V> ListenableFuture<V>forValue(V value)Create a new async result which exposes the given value fromFuture.get().Vget()Vget(long timeout, TimeUnit unit)booleanisCancelled()booleanisDone()
构造器详细资料
AsyncResult
public AsyncResult(@Nullable V value)
Create a new AsyncResult holder.- 参数:
value- the value to pass through
方法详细资料
isCancelled
public boolean isCancelled()
- 指定者:
isCancelled在接口中Future<V>
get
@Nullable public V get() throws ExecutionException
- 指定者:
get在接口中Future<V>- 抛出:
ExecutionException
get
@Nullable public V get(long timeout, TimeUnit unit) throws ExecutionException
- 指定者:
get在接口中Future<V>- 抛出:
ExecutionException
addCallback
public void addCallback(ListenableFutureCallback<? super V> callback)
从接口复制的说明:ListenableFutureRegister the givenListenableFutureCallback.- 指定者:
addCallback在接口中ListenableFuture<V>- 参数:
callback- the callback to register
addCallback
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)
从接口复制的说明:ListenableFutureJava 8 lambda-friendly alternative with success and failure callbacks.- 指定者:
addCallback在接口中ListenableFuture<V>- 参数:
successCallback- the success callbackfailureCallback- the failure callback
completable
public CompletableFuture<V> completable()
从接口复制的说明:ListenableFutureExpose thisListenableFutureas a JDKCompletableFuture.- 指定者:
completable在接口中ListenableFuture<V>
forValue
public static <V> ListenableFuture<V> forValue(V value)
Create a new async result which exposes the given value fromFuture.get().- 参数:
value- the value to expose- 从以下版本开始:
- 4.2
- 另请参阅:
Future.get()
forExecutionException
public static <V> ListenableFuture<V> forExecutionException(Throwable ex)
Create a new async result which exposes the given exception as anExecutionExceptionfromFuture.get().- 参数:
ex- the exception to expose (either an pre-builtExecutionExceptionor a cause to be wrapped in anExecutionException)- 从以下版本开始:
- 4.2
- 另请参阅:
ExecutionException