石英CronTrigger-发射时间

时间:2019-01-12 17:40:58

标签: java cron quartz

我正在使用石英cron表达式构建n个计划事件,我有开始日期和结束日期,但是,当创建一个表达式时,第二个事件(getNextValidTimeAfter)是错误的...

  1. 08-03-19 08:00:00-第一次约会
  2. 05-04-19 08:00:00-错误的日期...
  3. 05-07-19 08:00:00
  4. 04-10-19 08:00:00

按照表达式

0 0 8吗? 1/3 FRI#1 *

  org.quartz.CronExpression expression = new org.quartz.CronExpression(cronExpression.getExpression());

    List<Schedule> scheduleList = new ArrayList<>();

    Date nextExecutionDate = cronExpression.getStartDate();

    boolean first = true;

    while (true) {

        Schedule schedule = new Schedule();
        schedule.setStatus(Enums.StatusSchedule.PROGRAMADO);
        schedule.setCronExpression(cronExpression);
        schedule.setServiceOrderType(cronExpression.getServiceOrderType());
        schedule.setEstimatedTime(cronExpression.getEstimatedTime());

        if (first == false)
            nextExecutionDate = expression.getNextValidTimeAfter(nextExecutionDate);
        else
            first = false;

        if (cronExpression.getEndDate().compareTo(nextExecutionDate) <= 0)
            break;

        schedule.setScheduleDate(nextExecutionDate);

        if (CollectionUtils.isEmpty(schedule.getScheduleItems()))
            schedule.setScheduleItems(new ArrayList<>());

        for (GenericShelfData genericShelfData : genericShelfDataList) {

            ScheduleItem scheduleItem = new ScheduleItem();
            scheduleItem.setStatus(Enums.StatusSchedule.PROGRAMADO);
            scheduleItem.setSchedule(schedule);
            scheduleItem.setGenericShelfData(genericShelfData);
            scheduleItem.setScheduleSeparate(Enums.YesOrNo.NAO);
            schedule.getScheduleItems().add(scheduleItem);
        }

        scheduleList.add(schedule);
    }

1 个答案:

答案 0 :(得分:0)

我的表达是错误的...正确是.. 0 0 8吗? 3/3 FRI#2 *

我使用此网站来构建表达式:https://www.freeformatter.com/cron-expression-generator-quartz.html