I have a job flow and I would like to run it as the following:
Job1 -> Job2 -> Job3
-> Job4 -> Job5
The job flow will be started from Job1.
After Job1 is successfully finished, Job1 will launch both Job2 and Job4.
Job2 and Job4 will run in parallel.
After Job2 is successfully finished, Job2 will launch Job3.
After Job4 is successfully finished, Job4 will launch Job5.
The following is the code snippet for job1.xml and job launcher class of Job1:
job1.xml
<bean id="uiJobListener"
class="com.joblaunch.UIJobListener">
<property name="vmInfoImportUIBatchLauncher" ref="vmInfoImportUIBatchLauncher" />
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="uiBatchLauncher"
class="com.joblaunch.UIBatchLauncher">
<property name="simpleJobLauncher" ref="simpleJobLauncher" />
<property name="jobLocator" ref="jobRegistry" />
<property name="jobTwo" value="Job2" />
<property name="jobFour" value="Job4" />
</bean>
<batch:job id="Job1" restartable="true">
<batch:step id="stp01">
<batch:tasklet ref="stp01Operator" />
<batch:next on="COMPLETED" to="stp02" />
</batch:step>
<batch:step id="stp02">
<batch:tasklet ref="stp02Result" />
</batch:step>
<batch:listeners>
<batch:listener ref="uiJobListener" />
</batch:listeners>
</batch:job>
UIJobLauncher.java
Job jobOne = jobLocator.getJob(jobTwo);
simpleJobLauncher.run(jobOne, builder.toJobParameters());
Job jobTwo = jobLocator.getJob(jobFour);
simpleJobLauncher.run(jobTwo, builder.toJobParameters());
The Problem
But, when I started Job1, Job1 launched Job2 and Job2 continued to Job3.
After Job3 is finished, Job1 launched Job4 and Job4 continued to Job5.
"Job2, Job3 " pair and "Job4, Job5" pair didn't run in parallel. Although Job1 launched Job4, job flow became as the following:
Job1 -> Job2 -> Job3 -> Job4 -> Job5
So, how can the spring batch jobs be run in parallel? Is there a way to run spring batch jobs in parallel both from Spring Batch Admin UI and Command Line?