Package org.springframework.web.context.request.async

# Class WebAsyncTask<V>

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

Type Parameters:
  `V` - the value type

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanFactoryAware`

public class WebAsyncTask<V> extends Object implements org.springframework.beans.factory.BeanFactoryAware
Holder for a `Callable`, a timeout value, and a task executor.

Since:
  3.2
Author:
  Rossen Stoyanchev, Juergen Hoeller, Sam Brannen

## Constructor Summary

Constructors
Constructor
Description
`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`.
`WebAsyncTask(Long timeout, org.springframework.core.task.AsyncTaskExecutor executor, Callable<V> callable)`
Create a `WebAsyncTask` with a timeout value, an executor instance, and a Callable.
`WebAsyncTask(Callable<V> callable)`
Create a `WebAsyncTask` wrapping the given `Callable`.

## Method Summary

Modifier and Type
Method
Description
`Callable<?>`
`getCallable()`
Return the `Callable` to use for concurrent handling (never `null`).
`org.springframework.core.task.AsyncTaskExecutor`
`getExecutor()`
Return the AsyncTaskExecutor to use for concurrent handling, or `null` if none specified.
`Long`
`getTimeout()`
Return the timeout value in milliseconds, or `null` if no timeout is set.
`void`
`onCompletion(Runnable callback)`
Register code to invoke when the async request completes.
`void`
`onError(Callable<V> callback)`
Register code to invoke for an error during async request processing.
`void`
`onTimeout(Callable<V> callback)`
Register code to invoke when the async request times out.
`void`
`setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)`
A `BeanFactory` to use for resolving an executor name.

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

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

## 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, org.springframework.core.task.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(org.springframework.beans.factory.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 `org.springframework.beans.factory.BeanFactoryAware`

### getExecutor

@Nullable public org.springframework.core.task.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.