org.springframework.scheduling.annotation

Class AsyncResult<V>

  • java.lang.Object
    • org.springframework.scheduling.annotation.AsyncResult<V>
  • Type Parameters:
    V - the value type
    All Implemented Interfaces:
    java.util.concurrent.Future<V>, ListenableFuture<V>


    public class AsyncResult<V>
    extends java.lang.Object
    implements ListenableFuture<V>
    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 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.

    Since:
    3.0
    Author:
    Juergen Hoeller, Rossen Stoyanchev
    See Also:
    Async, forValue(Object), forExecutionException(Throwable)
    • Constructor Detail

      • AsyncResult

        public AsyncResult(@Nullable
                           V value)
        Create a new AsyncResult holder.
        Parameters:
        value - the value to pass through
    • Method Detail

      • cancel

        public boolean cancel(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<V>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<V>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<V>
      • get

        @Nullable
        public V get()
                        throws java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<V>
        Throws:
        java.util.concurrent.ExecutionException
      • get

        @Nullable
        public V get(long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<V>
        Throws:
        java.util.concurrent.ExecutionException
      • addCallback

        public void addCallback(SuccessCallback<? super V> successCallback,
                                FailureCallback failureCallback)
        Description copied from interface: ListenableFuture
        Java 8 lambda-friendly alternative with success and failure callbacks.
        Specified by:
        addCallback in interface ListenableFuture<V>
        Parameters:
        successCallback - the success callback
        failureCallback - the failure callback
      • forValue

        public static <V> ListenableFuture<V> forValue(V value)
        Create a new async result which exposes the given value from Future.get().
        Parameters:
        value - the value to expose
        Since:
        4.2
        See Also:
        Future.get()
      • forExecutionException

        public static <V> ListenableFuture<V> forExecutionException(java.lang.Throwable ex)
        Create a new async result which exposes the given exception as an ExecutionException from Future.get().
        Parameters:
        ex - the exception to expose (either an pre-built ExecutionException or a cause to be wrapped in an ExecutionException)
        Since:
        4.2
        See Also:
        ExecutionException