Home > Software engineering >  How can I change di job CRON expression in order to run my Spring Batch job twice a week?
How can I change di job CRON expression in order to run my Spring Batch job twice a week?

Time:01-17

in a Spring Batch application on which I am working on I scheduled a job in this way:

@Scheduled(cron = "0 30 01 * * 7")
public void runUpdateNotaryListInfoJob() {
    LOGGER.info("SCHEDULED run of updateNotaryListInfoJob STARTED");
    Map<String, JobParameter> confMap = new HashMap<>();
    confMap.put("time", new JobParameter(System.currentTimeMillis()));
    JobParameters jobParameters = new JobParameters(confMap);
    try {
        jobLauncher.run(updateNotaryListInfoJob, jobParameters);
    }catch (Exception ex){
        LOGGER.error(ex.getMessage());
    }
}

This works fine and my job is runned every Sunday (day 7) at 01:30 of the night. Ok it is fine but now my client ask me to run it twice in a week (same time but in two different days). Is it possible to change the previous CRON expression so that my job is performed at 01:30 of every Wednesday and every Sunday?

CodePudding user response:

A schedule like cron = "0 30 01 * * 3,7" triggers every 3rd and 7th day of the week.

CodePudding user response:

You can use the following 0 30 1 ? * SUN,WED * which will be easier for some developer to read and understand when he sees it in the code.

It will run every Sunday and every Wednesday at 01:30am

You can verify it or further modify it here.

  •  Tags:  
  • Related