@Scheduled 任务线程是否应该在任务完成后销毁?

Does @Scheduled task threads should be destroyed once task is completed?

我们在 spring 启动应用程序中实施了计划任务,以从 MQ 读取消息。 在 IntelliJ 中调试时,我看到任务的线程已启动,然后在任务完成后进入 WAIT 状态。

这是正常现象还是任务完成后线程应该 stopped/destroyed? 此外,我们是否必须手动完成或 Spring 负责(任务代码中的某些内容正在阻止它)

Spring 使用线程池来管理调度程序。来自 Spring docs on Scheduling:

If you do not provide a pool-size attribute, the default thread pool has only a single thread. There are no other configuration options for the scheduler.

线程 "waiting" 因为它们回到了线程池中。 Spring 因此为我们解决了这个问题。根据this SO post,如果你使用多个Scheduler,你只需要配置线程池。