spring-framework / org.springframework.web.context.request.async / WebAsyncTask

WebAsyncTask

open class WebAsyncTask<V : Any> : BeanFactoryAware

Holder for a Callable, a timeout value, and a task executor.

Author
Rossen Stoyanchev

Author
Juergen Hoeller

Since
3.2

Constructors

<init>

WebAsyncTask(callable: Callable<V>)

Create a WebAsyncTask wrapping the given Callable.

WebAsyncTask(timeout: Long, callable: Callable<V>)

Create a WebAsyncTask with a timeout value and a Callable.

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

Create a WebAsyncTask with a timeout value, an executor name, and a Callable.

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

Create a WebAsyncTask with a timeout value, an executor instance, and a Callable.

Functions

getCallable

open fun getCallable(): Callable<*>

Return the Callable to use for concurrent handling (never null).

getExecutor

open fun getExecutor(): AsyncTaskExecutor

Return the AsyncTaskExecutor to use for concurrent handling, or null if none specified.

getTimeout

open fun getTimeout(): Long

Return the timeout value in milliseconds, or null if no timeout is set.

onCompletion

open fun onCompletion(callback: Runnable): Unit

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.

onError

open fun onError(callback: Callable<V>): Unit

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.

onTimeout

open fun onTimeout(callback: Callable<V>): Unit

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.

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

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.