0

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.

David Conrad
  • 15,432
  • 2
  • 42
  • 54
ravecoder
  • 181
  • 5
  • 16

1 Answers1

0

You're missing the @Autowired annotation on job2.

David Conrad
  • 15,432
  • 2
  • 42
  • 54
  • This worked- thank you! For some reason it runs the jobs sequentially though. Do you know how I could get the jobs to run in parallel? – ravecoder Mar 11 '19 at 18:52
  • @ravecoder I don't, but you may find some guidance here: https://stackoverflow.com/questions/45718888/spring-batch-running-multiple-jobs-in-parallel – David Conrad Mar 11 '19 at 18:54
  • Thanks for sharing David. Appreciate the help. – ravecoder Mar 11 '19 at 18:55