我已经为单个步骤实现了spring批处理分区,其中主步骤将其工作委托给几个从线程,然后这些从线程被并行执行。如下图所示。(参考Spring docs)

现在,如果我有多个并行执行的步骤怎么办?如何批量配置?我当前的配置是
<batch:job id="myJob" restartable="true" job-repository="jobRepository" >
<batch:listeners>
<batch:listener ref="myJoblistener"></batch:listener>
</batch:listeners>
<batch:step id="my-master-step">
<batch:partition step="my-step" partitioner="my-step-partitioner" handler="my-partitioner-handler">
</batch:partition>
</batch:step>
</batch:job>
<batch:step id="my-step" >
<batch:tasklet ref="myTasklet" transaction-manager="transactionManager" >
</batch:tasklet>
<batch:listeners>
<batch:listener ref="myStepListener"></batch:listener>
</batch:listeners>
</batch:step>我的架构图应该如下图所示:

我不确定是否可以使用spring batch.Any的想法,或者我无法实现it.Thank you。
发布于 2014-08-15 23:36:48
您可以尝试执行以下操作。
<batch:job id="myJob" restartable="true" job-repository="jobRepository" >
<batch:listeners>
<batch:listener ref="myJoblistener"></batch:listener>
</batch:listeners>
<batch:step id="my-master-step">
<batch:partition step="my-step" partitioner="my-step-partitioner" handler="my-partitioner-handler">
</batch:partition>
</batch:step>
</batch:job>
<batch:step id="my-step" >
<batch:job ref="MyChildJob" job-launcher="jobLauncher"
job-parameters-extractor="jobParametersExtractor" />
<batch:listeners>
<batch:listener ref="myStepListener"></batch:listener>
</batch:listeners>
</batch:step>
<batch:job id="MyChildJob" restartable="false"
xmlns="http://www.springframework.org/schema/batch">
<batch:step id="MyChildStep1" next="MyChildStep2">
<batch:tasklet ref="MyChildStep1Tasklet" transaction-manager="transactionManager" >
</batch:tasklet>
</batch:step>
<batch:step id="MyChildStep2" next="MyChildStep3">
<batch:tasklet ref="MyChildStep2Tasklet" transaction-manager="transactionManager" >
</batch:tasklet>
</batch:step>
<batch:step id="MyChildStep3">
<batch:tasklet ref="MyChildStep3Tasklet" transaction-manager="transactionManager" >
</batch:tasklet>
</batch:step>
</batch:job>发布于 2016-04-08 21:50:41
我有类似的需求,并使用下面的需求解决了它
<batch:job id="cycleJob">
<batch:step id="zStep" next="gStep">
<batch:partition partitioner="zPartitioner">
<batch:step>
<batch:tasklet throttle-limit="1">
<batch:chunk processor="itemProcessor" reader="zReader" writer="itemWriter" commit-interval="1">
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:handler task-executor="taskExecutor" grid-size="${maxThreads}" />
</batch:partition>
</batch:step>
<batch:step id="gStep" parent="zStep" next="yStep">
<batch:partition partitioner="gPartitioner">
<batch:step>
<batch:tasklet throttle-limit="1">
<batch:chunk processor="itemProcessor" reader="gReader" writer="itemWriter" commit-interval="1">
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:handler task-executor="taskExecutor" grid-size="${maxThreads}" />
</batch:partition>
</batch:step>
</batch:job>发布于 2020-11-12 21:28:40
回答晚了,但我终于找到了我最初在这里寻找的解决方案,使用flow而不是子作业。所以我想我也应该把它贴在这里。
<job id="myJob">
<step id="my-master-step">
<partition partitioner="my-step-partitioner">
<handler task-executor="my-partitioner-handler" />
<step>
<!-- For each partition, we run the complete flow -->
<flow parent="mainFlow" />
</step>
</partition>
</step>
</job>
<!-- The flow consists of several sequential steps (2 here) -->
<flow id="mainFlow">
<step id="MyChildStep1" next="MyChildStep2">
<!-- Here you can have a tasklet or a chunk of course -->
<tasklet ref="MyChildStep1Tasklet" />
</step>
<step id="MyChildStep2">
<!-- Same here -->
<tasklet ref="MyChildStep2Tasklet" />
</step>
</flow>
<bean id="MyChildStep1Tasklet" class="..." />
<bean id="MyChildStep1Tasklet" class="..." />我没有测试过并行运行它,但我看不出它为什么不能工作。
https://stackoverflow.com/questions/23357024
复制相似问题