我正在使用 spring 启动中的 async task executor 来分割我的数百万条记录数据,块大小为1000,网格大小为10 . 我使用前一步项目阅读器中的StepExecution获取分区数据的开始和结束索引(来自分区程序类),以便从数据库中获取特定的分区数据 .
问题是只读取和写入一个分区 .
例如:物品读者
beforeStep(StepExecution execution){
int startIndex = execution.getExecutionContext().getInt("startIndexValue")
int endIndex = execution.getExecutionContext().getInt("endIndexValue")
List testDataList = getTestDatabetween(startIndex, endIndex);
}
Item Reader遍历testData List并将testData值返回给writer
testData read()
{
if(!testData.isEmpty()){
testData = testDataList.get(testIndex);
testIndex++;
}
return testData;
}
TestData = Partition1,Partition2,Partition3
只读取,处理和写入最后一个分区3的分区 .
我希望同时读取所有分区 .
1 回答
这很可能是读者的线程安全问题 . 测试这种方法的一种方法是将gridsize减少到1并查看它是否处理 .
请务必确保它在
scope="step"
中,以确保为每个分区获取新实例 .