Class WebAsyncTask<V>

java.lang.Object
org.springframework.web.context.request.async.WebAsyncTask<V>
Type Parameters:
V - the value type
All Implemented Interfaces:
Aware, BeanFactoryAware

public class WebAsyncTask<V> extends Object implements BeanFactoryAware
Holder for a Callable, a timeout value, and a task executor.
Since:
3.2
Author:
Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
  • Constructor Details

    • WebAsyncTask

      public WebAsyncTask(Callable<V> callable)
      Create a WebAsyncTask wrapping the given Callable.
      Parameters:
      callable - the callable for concurrent handling
    • WebAsyncTask

      public WebAsyncTask(long timeout, Callable<V> callable)
      Create a WebAsyncTask with a timeout value and a Callable.
      Parameters:
      timeout - a timeout value in milliseconds
      callable - the callable for concurrent handling
    • WebAsyncTask

      public WebAsyncTask(@Nullable Long timeout, String executorName, Callable<V> callable)
      Create a WebAsyncTask with a timeout value, an executor name, and a Callable.
      Parameters:
      timeout - the timeout value in milliseconds; ignored if null
      executorName - the name of an executor bean to use
      callable - the callable for concurrent handling
    • WebAsyncTask

      public WebAsyncTask(@Nullable Long timeout, AsyncTaskExecutor executor, Callable<V> callable)
      Create a WebAsyncTask with a timeout value, an executor instance, and a Callable.
      Parameters:
      timeout - the timeout value in milliseconds; ignored if null
      executor - the executor to use
      callable - the callable for concurrent handling
  • Method Details

    • getCallable

      public Callable<?> getCallable()
      Return the Callable to use for concurrent handling (never null).
    • getTimeout

      @Nullable public Long getTimeout()
      Return the timeout value in milliseconds, or null if no timeout is set.
    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory)
      A BeanFactory to use for resolving an executor name.

      This factory reference will automatically be set when WebAsyncTask is used within a Spring MVC controller.

      Specified by:
      setBeanFactory in interface BeanFactoryAware
      Parameters:
      beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
      See Also:
    • getExecutor

      @Nullable public AsyncTaskExecutor getExecutor()
      Return the AsyncTaskExecutor to use for concurrent handling, or null if none specified.
    • onTimeout

      public void onTimeout(Callable<V> callback)
      Register code to invoke when the async request times out.

      This method is called from a container thread when an async request times out before the Callable has completed. The callback is executed in the same thread and therefore should return without blocking. It may return an alternative value to use, including an Exception or return RESULT_NONE.

    • onError

      public void onError(Callable<V> callback)
      Register code to invoke for an error during async request processing.

      This method is called from a container thread when an error occurred while processing an async request before the Callable has completed. The callback is executed in the same thread and therefore should return without blocking. It may return an alternative value to use, including an Exception or return RESULT_NONE.

      Since:
      5.0
    • onCompletion

      public void onCompletion(Runnable callback)
      Register code to invoke when the async request completes.

      This method is called from a container thread when an async request completed for any reason, including timeout and network error.