AndreaNobili
AndreaNobili

Reputation: 43077

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

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?

Upvotes: 0

Views: 471

Answers (1)

Valerij Dobler
Valerij Dobler

Reputation: 2804

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

Upvotes: 1

Related Questions