类 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-throughFuture
handle that can be used for method signatures which are declared with aFuture
return type for asynchronous execution.As of Spring 4.1, this class implements
ListenableFuture
, not just plainFuture
, along with the corresponding support in@Async
processing.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.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addCallback(ListenableFutureCallback<? super V> callback)
Register the givenListenableFutureCallback
.void
addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)
Java 8 lambda-friendly alternative with success and failure callbacks.boolean
cancel(boolean mayInterruptIfRunning)
CompletableFuture<V>
completable()
Expose thisListenableFuture
as a JDKCompletableFuture
.static <V> ListenableFuture<V>
forExecutionException(Throwable ex)
Create a new async result which exposes the given exception as anExecutionException
fromFuture.get()
.static <V> ListenableFuture<V>
forValue(V value)
Create a new async result which exposes the given value fromFuture.get()
.V
get()
V
get(long timeout, TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
构造器详细资料
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)
从接口复制的说明:ListenableFuture
Register the givenListenableFutureCallback
.- 指定者:
addCallback
在接口中ListenableFuture<V>
- 参数:
callback
- the callback to register
addCallback
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)
从接口复制的说明:ListenableFuture
Java 8 lambda-friendly alternative with success and failure callbacks.- 指定者:
addCallback
在接口中ListenableFuture<V>
- 参数:
successCallback
- the success callbackfailureCallback
- the failure callback
completable
public CompletableFuture<V> completable()
从接口复制的说明:ListenableFuture
Expose thisListenableFuture
as 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 anExecutionException
fromFuture.get()
.- 参数:
ex
- the exception to expose (either an pre-builtExecutionException
or a cause to be wrapped in anExecutionException
)- 从以下版本开始:
- 4.2
- 另请参阅:
ExecutionException