org.springframework.web.context.request.async

## Class WebAsyncTask<V>

- java.lang.Object
- - org.springframework.web.context.request.async.WebAsyncTask<V>

-     public class WebAsyncTask<V>
      extends Object

  Holder for a `Callable`, a timeout value, and a task executor.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebAsyncTask(Callable<V> callable)` Create a `WebAsyncTask` wrapping the given `Callable`.
    `WebAsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<V> callable)` Create a `WebAsyncTask` with a timeout value, an executor instance, and a Callable.
    `WebAsyncTask(long timeout, Callable<V> callable)` Create a `WebAsyncTask` with a timeout value and a `Callable`.
    `WebAsyncTask(Long timeout, String executorName, Callable<V> callable)` Create a `WebAsyncTask` with a timeout value, an executor name, and a `Callable`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Callable<?>` | `getCallable()` Return the `Callable` to use for concurrent handling, never `null`.
    `AsyncTaskExecutor` | `getExecutor()` Return the AsyncTaskExecutor to use for concurrent handling, or `null`.
    `Long` | `getTimeout()` Return the timeout value in milliseconds or `null` if not value is set.
    `void` | `onCompletion(Runnable callback)` Register code to invoke when the async request completes.
    `void` | `onTimeout(Callable<V> callback)` Register code to invoke when the async request times out.
    `void` | `setBeanFactory(BeanFactory beanFactory)` A `BeanFactory` to use to resolve an executor name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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` - timeout value in milliseconds
        `callable` - the callable for concurrent handling

    - #### WebAsyncTask

          public WebAsyncTask(Long timeout,
                      String executorName,
                      Callable<V> callable)

      Create a `WebAsyncTask` with a timeout value, an executor name, and a `Callable`.
      Parameters:
        `timeout` - timeout value in milliseconds; ignored if `null`
        `callable` - the callable for concurrent handling

    - #### WebAsyncTask

          public WebAsyncTask(Long timeout,
                      AsyncTaskExecutor executor,
                      Callable<V> callable)

      Create a `WebAsyncTask` with a timeout value, an executor instance, and a Callable.
      Parameters:
        `timeout` - timeout value in milliseconds; ignored if `null`
        `callable` - the callable for concurrent handling

  - ### Method Detail

    - #### getCallable

          public Callable<?> getCallable()

      Return the `Callable` to use for concurrent handling, never `null`.

    - #### getTimeout

          public Long getTimeout()

      Return the timeout value in milliseconds or `null` if not value is set.

    - #### getExecutor

          public AsyncTaskExecutor getExecutor()

      Return the AsyncTaskExecutor to use for concurrent handling, or `null`.

    - #### setBeanFactory

          public void setBeanFactory(BeanFactory beanFactory)

      A `BeanFactory` to use to resolve an executor name. Applications are not expected to have to set this property when `WebAsyncTask` is used in a Spring MVC controller.

    - #### 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`.

    - #### 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.