Top Description Fields Constructors Methods
org.springframework.scheduling.annotation

public Class AsyncResult<V>

extends Object
implements ListenableFuture<V>
Class Inheritance
All Implemented Interfaces
org.springframework.util.concurrent.ListenableFuture, java.util.concurrent.Future
Annotations
@Deprecated
since:6.0
Type Parameters
<V>
the value type
Imports
java.util.concurrent.CompletableFuture, .ExecutionException, .Future, .TimeUnit, org.springframework.lang.Nullable, org.springframework.util.concurrent.FailureCallback, .ListenableFuture, .ListenableFutureCallback, .SuccessCallback

Deprecated

since 6.0.

as of 6.0, in favor of CompletableFuture

A pass-through Future handle that can be used for method signatures which are declared with a Future return type for asynchronous execution.

As of Spring 4.1, this class implements ListenableFuture, not just plain java.util.concurrent.Future, along with the corresponding support in @Async processing.

As of Spring 4.2, this class also supports passing execution exceptions back to the caller.

Authors
Juergen Hoeller, Rossen Stoyanchev
Since
3.0
See Also
Async, forValue(Object), forExecutionException(Throwable)

Field Summary

Modifier and TypeField and Description
private final Throwable
private final V

Constructor Summary

AccessConstructor and Description
public
AsyncResult(V
the value to pass through
value
)

Create a new AsyncResult holder.

private
AsyncResult(V
the value to pass through
value
,
Throwable ex)

Create a new AsyncResult holder.

Method Summary

Modifier and TypeMethod and Description
public void
addCallback(ListenableFutureCallback<? super V>
the callback to register
callback
)

Implements org.springframework.util.concurrent.ListenableFuture.addCallback.

References Deprecated ListenableFutureCallback is deprecated or references (maybe indirectly) at least one deprecated element.

Register the given ListenableFutureCallback.

public void
addCallback(SuccessCallback<? super V>
the success callback
successCallback
,
FailureCallback
the failure callback
failureCallback
)

Implements org.springframework.util.concurrent.ListenableFuture.addCallback.

References Deprecated SuccessCallback and FailureCallback are deprecated or reference (maybe indirectly) at least one deprecated element.

Java 8 lambda-friendly alternative with success and failure callbacks.

public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public CompletableFuture<V>
private static Throwable

Returns:

the exposed exception
exposedException
(Throwable
the original as given to forExecutionException
original
)

Determine the exposed exception: either the cause of a given ExecutionException, or the original exception as-is.

public static <V> ListenableFuture<V>
forExecutionException(Throwable
the exception to expose (either an pre-built ExecutionException or a cause to be wrapped in an ExecutionException)
ex
)
References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

Create a new async result which exposes the given exception as an ExecutionException from Future#get().

public static <V> ListenableFuture<V>
forValue(V
the value to expose
value
)
References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

Create a new async result which exposes the given value from Future#get().

public V
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

public V
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executionExceptionback to summary
private final Throwable executionException
Annotations
@Nullable
valueback to summary
private final V value
Annotations
@Nullable

Constructor Detail

AsyncResultback to summary
public AsyncResult(V value)

Create a new AsyncResult holder.

Parameters
value:V

the value to pass through

AsyncResultback to summary
private AsyncResult(V value, Throwable ex)

Create a new AsyncResult holder.

Parameters
value:V

the value to pass through

Method Detail

addCallbackback to summary
public void addCallback(ListenableFutureCallback<? super V> callback)

Implements org.springframework.util.concurrent.ListenableFuture.addCallback.

Doc from org.springframework.util.concurrent.ListenableFuture.addCallback.

References Deprecated

ListenableFutureCallback is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Register the given ListenableFutureCallback.

Parameters
callback:ListenableFutureCallback<? super V>

the callback to register

Annotations
@Override
addCallbackback to summary
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)

Implements org.springframework.util.concurrent.ListenableFuture.addCallback.

Doc from org.springframework.util.concurrent.ListenableFuture.addCallback.

References Deprecated

SuccessCallback and FailureCallback are deprecated or reference (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Java 8 lambda-friendly alternative with success and failure callbacks.

Parameters
successCallback:SuccessCallback<? super V>

the success callback

failureCallback:FailureCallback

the failure callback

Annotations
@Override
cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning:boolean

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
completableback to summary
public CompletableFuture<V> completable()

Overrides default org.springframework.util.concurrent.ListenableFuture.completable.

Doc from org.springframework.util.concurrent.ListenableFuture.completable.

Expose this ListenableFuture as a JDK CompletableFuture.

Annotations
@Override
exposedExceptionback to summary
private static Throwable exposedException(Throwable original)

Determine the exposed exception: either the cause of a given ExecutionException, or the original exception as-is.

Parameters
original:Throwable

the original as given to forExecutionException

Returns:Throwable

the exposed exception

forExecutionExceptionback to summary
public static <V> ListenableFuture<V> forExecutionException(Throwable ex)

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Create a new async result which exposes the given exception as an ExecutionException from Future#get().

Parameters
ex:Throwable

the exception to expose (either an pre-built ExecutionException or a cause to be wrapped in an ExecutionException)

Since
4.2
See Also
ExecutionException
forValueback to summary
public static <V> ListenableFuture<V> forValue(V value)

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Create a new async result which exposes the given value from Future#get().

Parameters
value:V

the value to expose

Since
4.2
See Also
Future#get()
getback to summary
public V get() throws ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:V

the computed result

Annotations
@Override
@Nullable
Exceptions
ExecutionException:
if the computation threw an exception
getback to summary
public V get(long timeout, TimeUnit unit) throws ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:V

the computed result

Annotations
@Override
@Nullable
Exceptions
ExecutionException:
if the computation threw an exception
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override