Class WebAsyncTask<V>
- java.lang.Object
- org.springframework.web.context.request.async.WebAsyncTask<V>
- All Implemented Interfaces:
Aware,BeanFactoryAware
public class WebAsyncTask<V> extends Object implements BeanFactoryAware
Holder for aCallable, a timeout value, and a task executor.- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Juergen Hoeller
Constructor Summary
Constructors Constructor Description WebAsyncTask(long timeout, Callable<V> callable)Create aWebAsyncTaskwith a timeout value and aCallable.WebAsyncTask(Long timeout, String executorName, Callable<V> callable)Create aWebAsyncTaskwith a timeout value, an executor name, and aCallable.WebAsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<V> callable)Create aWebAsyncTaskwith a timeout value, an executor instance, and a Callable.WebAsyncTask(Callable<V> callable)Create aWebAsyncTaskwrapping the givenCallable.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Callable<?>getCallable()Return theCallableto use for concurrent handling (nevernull).AsyncTaskExecutorgetExecutor()Return the AsyncTaskExecutor to use for concurrent handling, ornullif none specified.LonggetTimeout()Return the timeout value in milliseconds, ornullif no timeout is set.voidonCompletion(Runnable callback)Register code to invoke when the async request completes.voidonTimeout(Callable<V> callback)Register code to invoke when the async request times out.voidsetBeanFactory(BeanFactory beanFactory)ABeanFactoryto use for resolving an executor name.
Constructor Detail
WebAsyncTask
public WebAsyncTask(Callable<V> callable)
Create aWebAsyncTaskwrapping the givenCallable.- Parameters:
callable- the callable for concurrent handling
WebAsyncTask
public WebAsyncTask(long timeout, Callable<V> callable)
Create aWebAsyncTaskwith a timeout value and aCallable.- Parameters:
timeout- a timeout value in millisecondscallable- the callable for concurrent handling
WebAsyncTask
public WebAsyncTask(Long timeout, String executorName, Callable<V> callable)
Create aWebAsyncTaskwith a timeout value, an executor name, and aCallable.- Parameters:
timeout- timeout value in milliseconds; ignored ifnullexecutorName- the name of an executor bean to usecallable- the callable for concurrent handling
WebAsyncTask
public WebAsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<V> callable)
Create aWebAsyncTaskwith a timeout value, an executor instance, and a Callable.- Parameters:
timeout- timeout value in milliseconds; ignored ifnullexecutor- the executor to usecallable- the callable for concurrent handling
Method Detail
getCallable
public Callable<?> getCallable()
Return theCallableto use for concurrent handling (nevernull).
getTimeout
public Long getTimeout()
Return the timeout value in milliseconds, ornullif no timeout is set.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
ABeanFactoryto use for resolving an executor name.This factory reference will automatically be set when
WebAsyncTaskis used within a Spring MVC controller.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Parameters:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- See Also:
BeanInitializationException
getExecutor
public AsyncTaskExecutor getExecutor()
Return the AsyncTaskExecutor to use for concurrent handling, ornullif 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
Callablehas completed. The callback is executed in the same thread and therefore should return without blocking. It may return an alternative value to use, including anExceptionor returnRESULT_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.