首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多步骤并行的Spring batch Partitioning?

多步骤并行的Spring batch Partitioning?
EN

Stack Overflow用户
提问于 2014-04-29 14:23:15
回答 3查看 13.1K关注 0票数 5

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

现在,如果我有多个并行执行的步骤怎么办?如何批量配置?我当前的配置是

代码语言:javascript
复制
 <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。

EN

回答 3

Stack Overflow用户

发布于 2014-08-15 23:36:48

您可以尝试执行以下操作。

代码语言:javascript
复制
 <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>
票数 3
EN

Stack Overflow用户

发布于 2016-04-08 21:50:41

我有类似的需求,并使用下面的需求解决了它

代码语言:javascript
复制
<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>
票数 0
EN

Stack Overflow用户

发布于 2020-11-12 21:28:40

回答晚了,但我终于找到了我最初在这里寻找的解决方案,使用flow而不是子作业。所以我想我也应该把它贴在这里。

代码语言:javascript
复制
    <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="..." />

我没有测试过并行运行它,但我看不出它为什么不能工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23357024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档