如何并行运行 spring 批处理作业 [英] How to run spring batch jobs in parallel

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

问题描述

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

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());

问题

但是,当我启动 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 作业如何并行运行呢?有没有办法同时从 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?

推荐答案

工作无法按照您的要求自然管理.
您必须创建一个新的超级作业并使用 'Splitflow' 根据您的喜好配置重定向作业.
当然拆分适用于步骤而不适用于作业,但 SB 有可能使用 JobStep
按照官方文档和关于网络分裂的例子,你应该可以毫无问题地解决你的问题

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 批处理作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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