Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quartz - fixed interval with initial delay

On spring scheduler, this is what I wanted to achieved:

@Scheduled(initialDelay = 1000, fixedDelay = 5000)

I'm moving to quartz, and I cannot seem to find the equivalent API for the initial delay.

TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(5000));

Any ideas how I can add the delay?

like image 703
lorraine Avatar asked Dec 07 '25 14:12

lorraine


1 Answers

Use TriggerBuilder::startAt

Trigger trigger = newTrigger()
  .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(5000))
  .startAt(nowPlusDelay(5_000))
.build();

Where nowPlusDelay(int) returns a Date.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!