2

In my Spring program, I have a Scheduled task.

@Scheduled(cron = "0 0 0 2 * *") // hardcoded schedule
public void executeBatchJob() {
    batchJob.execute();
}

I have a specification change and now have to let the user freely configure the date and time of execution via an API.

One way I came up was to run a scheduled task every morning at 0:00 and check if the date is indeed the date of execution. If true, check the time of execution and schedule the batch job to run at that time of the day.

Is there a "Spring" way of achieving this?

cozyconemotel
  • 1,121
  • 2
  • 10
  • 22

1 Answers1

0

Triggers can be used to configure the scheduled jobs.

From the docs

The basic idea of the Trigger is that execution times may be determined based on past execution outcomes or even arbitrary conditions.

Check out this answer for detailed explanation.

Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78