我是 Spring 批处理的新手,所以也许我错了,但我不明白为什么 itemWriter 中的 write 方法需要数据列表:
void write(List<? extends T> items) throws Exception;
如果我首先理解这个过程是 itemReader,它读取项目列表。在第一次迭代中读取第一个项目等等......下一步是从 itemReader 获取数据的 itemProcessor。然后有一些处理和 itemProcessor 返回我们想要保存在某个地方的新类。所以最后一步是 itemWriter,它获取返回 itemProcessor 的此类。所以我不知道 itemWriter 何时获取数据列表。当我调试我的简单示例项目时,此列表中仍然只有一项。请有人解释一下
非常感谢
最佳答案
答案就在这个sequence diagram from the Spring Batch documentation .
如果这还不够清楚,文档(再次!)解释说 Spring 使用面向 block 的处理风格:
Spring Batch uses a 'Chunk Oriented' processing style within its most common implementation. Chunk oriented processing refers to reading the data one at a time, and creating 'chunks' that will be written out, within a transaction boundary.
其实Spring Batch的文档还是挺不错的。如果您刚开始使用 Spring Batch,我建议您阅读它。
关于java - 为什么 spring batch itemWriter 有方法写数据列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18381781/