简体   繁体   中英

Cron expression to run the task at 11am finished at 11pm

I need cron expression, to schedule my task. The task execution should start every day at 11am and should be executed every minute till 11pm( the last execution time).

Currently, I don't know how to set that last execution should be at 23:00.

* * 11-23 * * * - According to this expression the task would be run from 11:00 till 23:59.

* * 11-22 * * * - According to this expression the task would be run from 11:00 till 22:59. So the last execution for 23:00 is missed.

Please, tell me how can I solve this.

I have find work around for the issue. The solution is to create two cron expression:

  1. 0 * 11-22 * * * - this will start at 11am and finish at 22:59pm.

  2. 0 0 23 * * * - this task will start only once every day at 23:00.

So, my code now look like this:

@Scheduled(cron = "0 * 11-22 * * *")
  public void processPerformances() {
    // do something();

  }

  @Scheduled(cron = "0 0 23 * * *")
  public void processPerformancesLastTime() {
    processPerformances();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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