【问题标题】:Spring batch how to run a job in loop until it meets a condition?Spring批处理如何循环运行作业直到满足条件?
【发布时间】:2018-09-03 09:21:12
【问题描述】:
<job id="firstJob" restartable="true"
    xmlns="http://www.springframework.org/schema/batch">
    <step id="FirstStep">
        <tasklet>
            <chunk reader="read" writer="write"
                commit-interval="1" />
        </tasklet>
    </step>
</job>



<job id="second_job" restartable="false"
    xmlns="http://www.springframework.org/schema/batch">
    <step id="second_step" ">
        <tasklet>
            <chunk reader="reader_again" writer="writera_gain"
                commit-interval="500" />
        </tasklet>      
</job>

我在这里有两份工作(我的实际代码中有 3 份)。我想运行第一个作业以检查数据库中的某些值,并且仅在找到该值后才执行。为此,我希望它继续循环,直到它可以找到数据然后继续。我怎样才能通过 Spring Batch xml 做到这一点?有没有更好的方法来做到这一点?

此外,由于代码库的大小,我无法更改结构,即将两个作业分为两个步骤。

【问题讨论】:

    标签: java spring spring-boot spring-batch batch-processing


    【解决方案1】:

    是的,一个作业的控制流可以通过“外部化流定义”定向到另一个作业。您可以在第一份工作中简单地使用 While(condition),然后指定流程以达到第二份工作

    一种方法是简单地将流声明为对其他流的引用:

    <job id="job">
       <flow id="job1.flow1" parent="flow1" next="step3"/>
       <step id="step3" parent="s3"/>
    </job>
    
    <flow id="flow1">
       <step id="step1" parent="s1" next="step2"/>
       <step id="step2" parent="s2"/>
    </flow>
    

    https://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html#external-flows的详细信息

    【讨论】:

      猜你喜欢
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 2014-06-20
      • 2016-05-02
      • 2016-04-12
      • 2018-06-29
      相关资源
      最近更新 更多