2
votes

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?

1

1 Answers

4
votes

Jobs can't naturally managed as you ask.
You have to create a new super job and using a 'Split flow' configuration redirect job as you prefer.
Of course split works for steps and not for jobs, but SB has the possibility to wrap a job into a step using a JobStep
Follow official doc and examples about split around the net and you should be able to solve your problem without problem