如何并行运行Spring Batch作业 [英] How to run spring batch jobs in parallel

查看:156
本文介绍了如何并行运行Spring Batch作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作流程,我想按以下方式运行它:

I have a job flow and I would like to run it as the following:

Job1 -> Job2 -> Job3  
     -> Job4 -> Job5

作业流程将从Job1开始. 成功完成Job1之后,Job1将启动Job2和Job4.
Job2和Job4将并行运行.
Job2成功完成后,Job2将启动Job3.
Job4成功完成后,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.

以下是job1.xml和Job1的工作启动器类的代码段:

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

UIJobLauncher.java

Job jobOne = jobLocator.getJob(jobTwo);
simpleJobLauncher.run(jobOne, builder.toJobParameters());

Job jobTwo = jobLocator.getJob(jobFour);
simpleJobLauncher.run(jobTwo, builder.toJobParameters());

问题

The Problem

但是,当我启动Job1时,Job1启动了Job2,而Job2继续到Job3.
Job3完成后,Job1启动Job4,Job4继续到Job5.

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"对和"Job4,Job5"对不是并行运行的. 尽管Job1启动了Job4,但工作流程如下:

"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

那么,弹簧批处理作业如何并行运行? 是否可以从Spring Batch Admin UI和命令行并行运行Spring Batch作业?

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?

推荐答案

工作不能自然地按您的要求进行管理.
您必须创建一个新的超级作业,并使用'Split流" 配置重定向作业.
当然,拆分仅适用于步骤而不适用于作业,但是SB可以使用

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

这篇关于如何并行运行Spring Batch作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆