从分区步骤分区 - Spring Batch

时间:2017-06-23 05:38:18

标签: spring-batch batch-processing

我有一个场景,我需要在两个步骤中引入并行性,第二个应该从第一个产生多个线程,这些线程也有按照分区的线程数。

历史档案或活动记录的暂停记录就是这种情况 - 每个活动的出租车都会暂停。

目前通过步骤循环使用如下决定程序实现同样的目的

<batch:job id="agreementDataArchiveJob">
        <batch:step id="getActiveRecordStep">
            <batch:tasklet ref="getActiveRecordsTask"
                task-executor="taskExecutor" />
            <batch:next on="CONTINUE" to="getSuspendedRecordsStep"></batch:next>
            <batch:end on="COMPLETED" />
        </batch:step>
        <batch:step id="getSuspendedRecordsStep">
            <batch:tasklet ref="getSuspendedRecordsToArchiveTask"
                task-executor="taskExecutor" />
            <batch:next on="CONTINUE" to="archiveSuspendedDataStep"></batch:next>
            <batch:next on="COMPLETED" to="archivalStepDecider"/>
        </batch:step>
        <batch:step id="archiveSuspendedDataStep" next="archivalStepDecider">
            <batch:partition partitioner="archiveSuspendedDataPartitioner"
                handler="suspendedAgreementArchivalPartitionHandler" step="suspendedAgreementArchival">
            </batch:partition>
        </batch:step>
        <batch:decision decider="archivalStepExecutionDecider"
            id="archivalStepDecider">
            <batch:next on="CONTINUE" to="getSuspendedRecordsStep"></batch:next>
            <batch:end on="COMPLETED"></batch:end>
        </batch:decision>
        <batch:listeners>
            <batch:listener ref="archivalBatchListener"></batch:listener>
        </batch:listeners>
    </batch:job>

这里有一个活动,它的被挂起将被清除多个线程 - 继续下一个活动。     要优化性能,需要以这样的方式实现并行,即同时处理多个活动记录 - 每个活动的id线程调用多个并行线程来删除其历史记录

<batch:job id="multilevelDataArchiveJob">
        <batch:step id="getActiveRecordStep">
            <batch:tasklet ref="getActiveRecordsTask"
                task-executor="taskExecutor" />
            <batch:next on="CONTINUE" to="getActiveIdsForConcurrentExecution"></batch:next>
            <batch:end on="COMPLETED"/> 
        </batch:step>
        <batch:step id="getActiveIdsForConcurrentExecution" next="processSuspendedIds">
            <batch:partition step="getSuspendedForActiveRecordStep" 
                partitioner="readActiveDataPartitioner" handler="activeRecordPartitionHandler" />
        </batch:step>
        <batch:step id="processSuspendedIds" parent="getActiveIdsForConcurrentExecution">
            <batch:partition partitioner="archiveSuspendedDataPartitioner"
                handler="suspendedDataArchivalPartitionHandler" step="suspendedDataArchival" />
        </batch:step>
</batch:job>

但即使正在为处理活动记录创建多个分区,这也是仅对一个活动执行第二个块步骤

我们如何更改配置以实现多级并行? 我们是否需要改变方法。

0 个答案:

没有答案