My spring boot batch application has a scheduler which schedules my batch job written in FirstBatchConfiguration class to run every hour.
I have another batch job which I have configured in SecondBatchConfiguration class in the same application which i will be scheduling to run once in a week, but I am not able to figure out how to schedule it in the same JobScheduler so that both jobs should run at their own scheduled times.
If someone could help me to achieve this.
My current scheduler is:
@Component
public class JobScheduler {
@Autowired
private JobLauncher jobLauncher;
@Autowired
private FirstBatchConfiguration firstBatchConfiguration;
@Scheduled(cron = "0 0 0/1 * * ?")
public void runJob() {
Map<String, JobParameter> confMap = new HashMap<>();
confMap.put("time", new JobParameter(System.currentTimeMillis()));
JobParameters jobParameters = new JobParameters(confMap);
final Logger logger = LoggerFactory.getLogger("applicationlogger");
try {
jobLauncher.run(firstBatchConfiguration.firstJob(), jobParameters);
} catch (JobExecutionAlreadyRunningException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException | org.springframework.batch.core.repository.JobRestartException e) {
logger.error(e.getMessage());
}
}
}