Java Quartz получает nextFireTime из выражения cronJAVA

Программисты JAVA общаются здесь
Anonymous
Java Quartz получает nextFireTime из выражения cron

Сообщение Anonymous »

Я пытаюсь вычислить время следующего выполнения выражения cronExpression с помощью Java Quartz, но для свойства nextFireTime всегда получается значение null.
Выражение Cron кажется допустимым. и я использую версию 2.3.2 для org.quartz-scheduler
что я делаю не так?

public LocalDateTime cronExpression(String cronExpression, LocalDateTime startDate) {
try {
CronExpression cron = new CronExpression(cronExpression);
CronTrigger trigger = TriggerBuilder.newTrigger()
.withSchedule(CronScheduleBuilder.cronSchedule(cron))
.startAt(Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant())).
build();

Date nextExecutionTime = trigger.getNextFireTime();
return nextExecutionTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
} catch (ParseException e) {
LOGGER.debug("Error parsing cron expression {}", e.getMessage());
} catch (Exception e) {
LOGGER.debug("Unexpected error {}", e.getMessage());
}
return null;
}

@Test
void test() throws ParseException {
String cronExpression = "0 0 10 1/1 * ? *";
LocalDateTime startDate = LocalDateTime.of(2024, 4, 1, 15, 0);

LocalDateTime nextExecutionTime = jobSchedulingService.calculateNextExecutionTime(cronExpression, startDate);

assertNotNull(nextExecutionTime);
assertEquals(startDate.plusHours(1), nextExecutionTime);
}



Подробнее здесь: https://stackoverflow.com/questions/782 ... expression

Вернуться в «JAVA»