简体   繁体   English

春季计划任务停止工作更长的时间

[英]Spring scheduled task stops working for a longer period of time

We have 10 scheduled tasks configured to run every 20 seconds with the following annotation (they are stopped at night, because depended systems reboot at 4 in the morning): 我们配置了10个计划的任务,每20秒运行一次,并带有以下注释(它们在晚上停止,因为相关系统在凌晨4点重新启动):

@Scheduled(cron = "*/20 * 0-3,5-23 * * *")
public void pollingMethod1() {
    ...
}
@Scheduled(cron = "*/20 * 0-3,5-23 * * *")
public void pollingMethod2() {
    ...
}
...

We have a thread pool taks scheduler configured with pool size 10: 我们有一个配置为池大小10的线程池taks调度程序:

@Configuration
public class SchedulerConfig implements SchedulingConfigurer {
    private final int POOL_SIZE = 10;

    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();

        threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
        threadPoolTaskScheduler.setThreadNamePrefix("polling-pool-");
        threadPoolTaskScheduler.initialize();
        threadPoolTaskScheduler.setAwaitTerminationSeconds(120);
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);

        scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
    }
}

Sometimes during the day one of the tasks does not get executed for one or two hours and then continues to be executed regularly. 有时,一天中的一项任务不会在一两个小时内执行,然后继续定期执行。 Is it possible that one the tasks is blocking other tasks? 一个任务有可能阻止其他任务吗? And how can I find out if this is the case? 我怎么知道是否是这种情况?

Suppost pollingMethod1 takes more than 20 seconds, then it might be executed by different threads at the same time, which causes other task be blocked. Suppost pollingMethod1需要20秒钟以上,然后它可能同时由不同的线程执行,这导致其他任务被阻塞。 If this is allowed, you should increase POOL_SIZE . 如果允许,则应增加POOL_SIZE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM