I have spring batch setup and I'm trying to run two jobs in parallel. I have one job working fine but when adding the second job it stops working. Job setup is as follows:
<job id="job">
<split id="split_1" task-executor="taskExecutor" next="step_4">
<flow>
<step id="step_1">
<tasklet ref="taskletStep_1"/>
</step>
</flow>
<flow>
<step id="step_2">
<tasklet ref="taskletStep_2"/>
</step>
</flow>
<flow>
<step id="step_3">
<tasklet ref="taskletStep_3"/>
</step>
</flow>
</split>
<step id="step_4">
<tasklet ref="taskletStep_3"/>
</step>
</job>
<job id="job2">
<split id="split_2" task-executor="taskExecutor" next="step_8">
<flow>
<step id="step_5">
<tasklet ref="taskletStep_4"/>
</step>
</flow>
<flow>
<step id="step_6">
<tasklet ref="taskletStep_5"/>
</step>
</flow>
<flow>
<step id="step_7">
<tasklet ref="taskletStep_6"/>
</step>
</flow>
</split>
<step id="step_8">
<tasklet ref="taskletStep_6"/>
</step>
</job>
When it's with one job it works fine. When I add the second job, first job works fine but the second job renders:
INFO 40904 --- [nio-8181-exec-1] c.j.b.p.c.JobLauncherController : The Job must not be null.
Job Launcher setup looks like this:
@RestController
public class JobLauncherController {
@Autowired
JobLauncher jobLauncher;
@Autowired
Job job;
Job job2;
@RequestMapping("/launchjob")
public String handle() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
try {
JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(job, jobParameters);
jobLauncher.run(job2, jobParameters);
} catch (Exception e) {
logger.info(e.getMessage());
}
return "Done";
}
}
Any suggestions to resolve this? Not sure what I'm missing.