Spring task execution and scheduling
Using threads in any web application is not easy when we are dealing with a long-running task. Sometimes, we need to run a task asynchronously or after a specific delay, and that can be accomplished by Spring's task execution and scheduling. The Spring Framework introduced abstractions for asynchronous execution and scheduling of tasks with the TaskExecutor
and TaskScheduler
interfaces.
TaskExecutor
Spring provides the TaskExecutor
interface as an abstraction for dealing with Executor
. The implementation classes of TaskExecutor
are as follows:
SimpleAsyncTaskExecutor
: This starts a new thread and executes it asynchronously. It does not reuse the thread.SyncTaskExecutor
: This executes each task synchronously in the calling thread. It does not reuse the thread.ConcurrentTaskExecutor
: This exposes bean properties for configuringjava.util.concurrent.Executor
.SimpleThreadPoolTaskExecutor
: This is a subclass ofSimpleThreadPool
ofQuartz
, which listens to Spring...