Spring Core framework provides abstraction of task execution. Task execution is referred as creating a new thread and perform some task in it. Spring's task execution abstraction hides implementation differences between Java SE 1.4, Java SE 5 and Java EE environments. Spring underlying implementation can be based on Java Executor framework or a simple Java thread or even it can be based on a third party library like Quartz.
The interfaces
Spring task execution is based on the TaskExecutor and it's sub-interfaces.
The diagram on the left is interactive and clickable, it will take you the api pages.
TaskExecutor is same as Executor interface.
AsyncTaskExecutor can handle Callable submission and returns Future.
AsyncListenableTaskExecutor returns ListenableFuture on task submission, which can attach listener to get callbacks on task completion. Deprecated since Spring 6.0 and added methods in AsyncTaskExecutor which return CompletableFuture. This class has been removed in Spring 7.0.
Submit a Runnable task for execution, receiving a ListenableFuture representing that task.
2
Submit a Callable task for execution, receiving a ListenableFuture representing that task.
AsyncListenableTaskExecutor has been deprecated in 6.0, in favor of AsyncTaskExecutor.submitCompletable(Runnable) and AsyncTaskExecutor.submitCompletable(Callable)
AsyncListenableTaskExecutor has been removed in Spring 7.0.
Called when the ListenableFuture completes with failure.
FailureCallback has been removed in Spring 7.0.
In this tutorial we have introduced commonly used task executors. There are more. Please checkout reference document TaskExecutor types list. In the next tutorial we will give examples for Spring TaskExecutor implementation.