lorraine batol
lorraine batol

Reputation: 6281

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?

Upvotes: 3

Views: 3283

Answers (1)

user11044402
user11044402

Reputation:

Use TriggerBuilder::startAt

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

Where nowPlusDelay(int) returns a Date.

Upvotes: 6

Related Questions