gpt4 book ai didi

java - 如何在 spring-batch 中拆分和加入流程以配置作业中的设置和拆卸步骤

转载 作者:行者123 更新时间:2023-12-03 13:10:16 27 4
gpt4 key购买 nike

我已经查看了Spring-batch flow / split after a step ,并发现 (a) 标记的解决方案未解析,因为拆分无法到达,并且 (b) 我的用例不同,因此答案的意图不同。

我还查看了How to configure mentioned use case using spring batch parallel step split flow? ,但解决方案是增加并行化,而不是拆分和加入线程。

这似乎是一个足够常见的用例,它应该是一个常见问题解答,但我还没有看到解决方案。

我有一个并行化的 spring-batch 作业,我想在其中添加设置和拆卸步骤。设置和拆解是单线程的,但主体工作是并行的。

随着时间的推移以不同的方式绘制:

start        setup
|
split -------
| |
some other
stuff stuff
| |
join -------
|
finish teardown

我开始的 spring-batch 作业 XML 是:

<batch:job id="myJob">

<batch:step id="step0001-setup">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100" allow-start-if-complete="true">
<batch:chunk reader="beforeJobScriptExecutor" writer="dummySinkWriter"
commit-interval="1" />
</batch:tasklet>
</batch:step>


<batch:split id="split1" task-executor="taskExecutor" next="step9999">

<batch:flow>
<batch:step id="step0003-one-thread"
allow-start-if-complete="true">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100">
<batch:chunk reader="myReader1" writer="myWriter1"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:flow>

<batch:flow>
<batch:step id="step0002-another-thread">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100">
<batch:chunk reader="myReader2" writer="myWriter2"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:flow>

</batch:split>


<batch:step id="step9999">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100" allow-start-if-complete="true">
<batch:chunk reader="afterJobScriptExecutor" writer="dummySinkWriter"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>

最佳答案

解决方案主要在这篇文章中概述:How to terminate Step within a Spring Batch Split Flow with a Decider

spring-batch 作业的最终文本是这样的:

<batch:job id="myJob">

<batch:step id="step0001-setup">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100" allow-start-if-complete="true">
<batch:chunk reader="beforeJobScriptExecutor" writer="dummySinkWriter"
commit-interval="1" />
</batch:tasklet>
<batch:end on="FAILED" />
<batch:next on="*" to="split1" />
</batch:step>


<batch:split id="split1" task-executor="taskExecutor" next="step9999">

<batch:flow>
<batch:step id="step0003-one-thread"
allow-start-if-complete="true">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100">
<batch:chunk reader="myReader1" writer="myWriter1"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:flow>

<batch:flow>
<batch:step id="step0002-another-thread">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100">
<batch:chunk reader="myReader2" writer="myWriter2"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:flow>

</batch:split>


<batch:step id="step9999">
<batch:tasklet transaction-manager="jtaTransactionManager"
start-limit="100" allow-start-if-complete="true">
<batch:chunk reader="afterJobScriptExecutor" writer="dummySinkWriter"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>

关于java - 如何在 spring-batch 中拆分和加入流程以配置作业中的设置和拆卸步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36318439/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com