【问题标题】:Scheduled task to run every 3 days at given time计划任务在给定时间每 3 天运行一次
【发布时间】:2015-05-19 12:33:04
【问题描述】:

我正在使用 Quartz 2 调度程序来调度任务。以下是我需要的。

  1. 在用户单击按钮时安排作业。
  2. 作业应安排在早上 8 点运行,每 3 天运行一次。

以下是我的编码方式。一旦用户单击 Web 应用程序中的按钮,它将执行(当然使用它的调度程序)

Trigger passportTrigger1 = newTrigger()
                 .withIdentity(passportTriggerKey1)
                 .withSchedule(simpleSchedule().withIntervalInHours(3*24).repeatForever()) 
                 .startAt(todayAt(8,0,0)).build();

但是你可以看到我使用了startAt(todayAt(8,0,0))。如果用户在今天上午 8 点之后打开调度程序会发生什么?作业将立即安排还是永远不会安排?

【问题讨论】:

    标签: java web-applications scheduled-tasks quartz-scheduler


    【解决方案1】:

    您也可以查看当前时间:如果是早上 8 点之前 startAt(todayAt(8, 0, 0) 否则 startAt(tomorrowAt(8, 0, 0))。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 2015-01-09
      相关资源
      最近更新 更多