Spring ThreadPoolTaskScheduler vs ThreadPoolTaskExecutor

The Spring documentation states that:

ThreadPoolTaskScheduler actually implements the Spring TaskExecutor interface, so that one instance can be used for asynchronous execution as soon as possible, as well as scheduled and potentially recurring executions.

So, what are the scenarios in which we would like to use an instance of ThreadPoolTaskExecutor for an instance of ThreadPoolTaskScheduler ?

I am currently using Spring XML. I create a bean of ThreadPoolTaskScheduler as follows:

 <task:scheduler id="myScheduler" pool-size="1"/> 

while the bean of the ThreadPoolTaskExecutor instance can be created as

 <task:executor id="executor" pool-size="10"/> 
+7
spring scheduled-tasks threadpoolexecutor task executor
source share
1 answer

The suggestion mentioned in the Spring documentation only says that you can use the scheduler to complete tasks, but that is not the main goal. A ThreadPoolTaskExecutor provides fine-grained configuration through a thread pool through corePoolSize , maxPoolSize , keepAliveSeconds and queueCapacity . A scheduler such as ThreadPoolTaskScheduler does not provide such a configuration.

Thus, the choice between these two methods comes down to the following question: do I need to complete or plan tasks?

+8
source share

All Articles