【问题标题】:Spring Batch Partitioning - All Threads Process Same RecordsSpring Batch Partitioning - 所有线程处理相同的记录
【发布时间】:2017-08-07 02:36:47
【问题描述】:

我正在使用 Spring Boot 中的 async task executor 对我的数百万条记录的数据进行分区,块大小为 1000,网格大小为 10。 我正在使用 Item Reader 之前步骤中的 StepExecution 获取分区数据(来自 Partitioner 类)的开始和结束索引,以便从数据库中获取特定的分区数据。

问题是只有一个分区被读写。

例如: 物品阅读器

beforeStep(StepExecution execution){
int startIndex = execution.getExecutionContext().getInt("startIndexValue")
int endIndex = execution.getExecutionContext().getInt("endIndexValue")
List testDataList = getTestDatabetween(startIndex, endIndex);
}

项目阅读器 遍历 testData List 并将 testData 值返回给 writer

testData read()
{
if(!testData.isEmpty()){
testData = testDataList.get(testIndex);
testIndex++;
}
return testData;
}

TestData = Partition1, Partition2, Partition3

只有最后一个分区 Partition3 被读取、处理和写入。

我希望同时读取所有分区。

【问题讨论】:

  • 您是否查看了 BATCH_STEP_EXECUTION 以查看是否创建了其他分区?您是否尝试过在调试中运行以查看 getTestDatabetwee 方法是否正在为您提交的范围拉回行?您是否尝试过添加日志记录?

标签: spring-boot spring-batch partitioning


【解决方案1】:

这很可能是您的阅读器的线程安全问题。测试这一点的一种方法是将网格大小减小到 1 并查看它是否可以处理。

请确保它在scope="step" 中,以确保您为每个分区获得一个新实例。

<bean id="yourReader" class="com.example.reader.YourReader" scope="step">
    <!-- properties -->
</bean>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 2018-10-24
    • 2021-07-10
    • 2016-12-15
    • 1970-01-01
    相关资源
    最近更新 更多