Spring 批处理如何 运行 循环中的作业直到满足条件?
Spring batch how to run a job in loop until it meets a condition?
<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 批处理 xml 做到这一点?有更好的方法吗?
此外,由于代码库的大小,我无法更改结构,即将两个作业分成两个步骤。
是的,一个作业的控制流可以通过 "Externalizing Flow Definitions" 定向到另一个作业。您可以简单地在第一份工作中使用 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
<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 批处理 xml 做到这一点?有更好的方法吗?
此外,由于代码库的大小,我无法更改结构,即将两个作业分成两个步骤。
是的,一个作业的控制流可以通过 "Externalizing Flow Definitions" 定向到另一个作业。您可以简单地在第一份工作中使用 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