Cron 表达式 运行 上午 11 点的任务在晚上 11 点完成

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

我需要 cron 表达式来安排我的任务。任务执行应在每天上午 11 点开始,并应每分钟执行一次,直到晚上 11 点(最后一次执行时间)。

目前,我不知道如何设置最后执行应该在23:00。

* * 11-23 * * * - 根据这个表达式,任务将从 11:00 到 23:59 运行。

* * 11-22 * * *- 根据这个表达式,任务将从 11:00 到 22:59 运行。所以错过了 23:00 的最后一次执行。

请告诉我如何解决这个问题。

我已找到解决此问题的方法。解决方案是创建两个 cron 表达式:

  1. 0 * 11-22 * * * - 这将从上午 11 点开始,在 22:59pm 结束。

  2. 0 0 23 * * * - 此任务每天只会在 23:00.

  3. 开始一次

所以,我的代码现在看起来像这样:

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

  }

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