Spring ThreadPoolTaskScheduler vs ThreadPoolTaskExecutor

后端 未结 1 1070
自闭症患者
自闭症患者 2021-02-04 04:43

It is mentioned in the Spring documentation that:

ThreadPoolTaskScheduler actually implements Spring\'s TaskExecutor interface a

1条回答
  •  天涯浪人
    2021-02-04 05:41

    • ThreadPoolTaskExecutor is a specialized class for executing tasks.
    • ThreadPoolTaskScheduler is a specialized class for scheduling tasks.

    The sentence you quoted in the Spring documentation is only saying that you can use a scheduler to execute tasks, but that it is not its main purpose. A ThreadPoolTaskExecutor provides fine-grained configuration over the thread pool through its corePoolSize, maxPoolSize, keepAliveSeconds and queueCapacity properties. A scheduler such as ThreadPoolTaskScheduler does not provide such configuration.

    As such, choosing between the two comes down the following question: do I need to execute or schedule execution of tasks?

    0 讨论(0)
提交回复
热议问题