Home  >  Q&A  >  body text

java - spring scheduled task execution exception

The task was originally executed at 1 am every day from Monday to Friday. After checking the log, I found that it was executed at 20:00 on Sunday. Find out the possible reasons. The server is a single-core CPU.
Supplement: In my scheduled task class There are two scheduled tasks AB. Task A is executed at 1 o'clock from Monday to Friday (@Scheduled(cron = "0 0 1 ? MON-FRI")), and task B is executed at 3 o'clock every day (@Scheduled(cron = " 0 0 3 ? *")), check the log and find that from Monday to Friday, task A is executed first and then task B, that is, B is executed without waiting until 3 o'clock; when it is on Saturday and Sunday Task B was executed at 3 o'clock at that time, but task A was executed at 20 o'clock on Sunday. . .

phpcn_u1582phpcn_u15822713 days ago964

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-17 10:04:53

    I guess you did not specify the pool size of the scheduled task, so by default all schedules share one thread. You need to specify the pool size of the schedule

    xml

    <task :annotation-driven scheduler ="myScheduler" />
    <task :scheduler id ="myScheduler" pool-size ="10" />

    bean

      @Bean(destroyMethod = "shutdown")
        public Executor taskScheduler() {
            return Executors.newScheduledThreadPool(10);
        }

    Addition:
    Sharing a thread will cause serious problems. If task A is not executed within 2 hours, the execution time of task B will be delayed or even not executed.

    reply
    0
  • Cancelreply