弹簧分批流/分步后 [英] Spring-batch flow / split after a step

查看:112
本文介绍了弹簧分批流/分步后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个包含以下过程的spring-batch解决方案:

I am building a spring-batch solution that contains the following process:

步骤1:将列表拆分为多个列表
步骤2:子列表
步骤3:合并子列表

step 1 : split a list into multiple lists step 2 : process each sub-list step 3 : merge sub-lists

生成的子列表可以并行处理,根据spring-batch文档,这是支持的。很遗憾,我只能找到以并行步骤开始的春季批处理示例作业,而不是按顺序开始的示例。

The generated sub-lists can be processed in parallel, and according to the spring-batch documentation this is supported. Sadly I can only find spring-batch example jobs that start with parallel steps, not examples that start out sequentially.

以下作业将无法编译。 Spring给我一个错误:'无法解析step2'

The following job will not compile. Spring gives me an error: 'cannot resolve step2'

<batch:job id="webServiceJob2">
    <batch:step id="step1" next="step2"></batch:step>
    <batch:split id="step2" next="step3"></batch:split>
    <batch:step id="step3"></batch:step>
</batch:job>

那么如何配置一个作业,首先运行一个步骤,而不是运行一些步骤平行,然后运行最后一步?

So how can I configure a job to first run a single step, than run a number of steps in parallel, and then run a last single step?

推荐答案

我偶然发现了这个问题,这个答案到了有点(一年)晚了,但在这里我走...

I've stumbled upon this question asking about how split works, and maybe this answer arrives a bit (one year) late, but here I go...

问题是split本身不是一个步骤,命名(并引用)它:

The issue there is "split" is not a step by itself, but you were naming (and referencing) it as it was:

<batch:job id="webServiceJob2">
    <batch:step id="step1" next="step2"></batch:step>
    <batch:split id="step2" next="step3"></batch:split> <!-- This is not a step -->
    <batch:step id="step3"></batch:step>
</batch:job>

正确的语法是:

<batch:job id="webServiceJob2">
    <batch:step id="step1" next="step2"></batch:step>
    <batch:split id="split_step2" next="step3">
        <flow> 
             <step id="step2_A_1" ... next="step2_A_2"/>
             <step id="step2_A_2" ... />
        </flow>
        <flow> 
             <step id="step2_B_1" ... />
        </flow>
    </batch:split>
    <batch:step id="step3"></batch:step>
</batch:job>

但这不是你想要实现的,因为 split 声明,你必须在编译时设置将要执行的并行步骤的确切数目,并且split的目的是在每个流中使用不同的步骤,而不是调用同一个流的几次。

But this is not what you want to achieve, because by split declarations you have to set in compile time the exact number of parallel steps that will be executed, and the purpose of split is using different steps in each flow instead calling several times the same one.

您应该检查有关缩放和并行处理分区步骤似乎是您的需求的一个很好的候选。

You should check the documentation about Scaling and Parallel processes, the partition step seems a good candidate for your requirements.

这篇关于弹簧分批流/分步后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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