首页 文章

Spring批处理并行执行多个步骤?

提问于
浏览
5

我已经为一个步骤实现了 spring 批处理分区,其中主步骤将其工作委托给多个并行执行的从属线程 . 如下图所示 . (参考Spring docs
enter image description here
现在如果我有多个并行执行的步骤怎么办?如何在批量配置中配置它们?我目前的配置是

<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>

我的架构图应该如下图所示:
enter image description here

即使有可能使用 spring 批,我也不确定 . 任何想法或者我都想实现它 . 谢谢 .

2 回答

  • 0

    You can try the following.

    <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

    我有类似的要求,并使用以下要求解决它

    <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>
    

相关问题