我有一个简单的Spring批处理作业,只有几个步骤,最后一步是写报告,所以我有ItemReader,ItemProcessor和ItemWriter。ItemWriter write by chunk取决于步骤中定义的块编号,但我需要等待,直到获得所有项目,然后编写最终报告。我该怎么做呢?
public class ReportItemWriter implements ItemWriter<ReportItem> {
private List<ReportItem> allItems = Lists.newArrayList();
...
public void write(List<? extends ReportItem> reportItems) throws Exception {
allItems.addAll(reportItems);
writeReport(allItems); <-- here it only write chunk of items to the report
}发布于 2018-12-01 00:32:17
如果你的作者有@JobScope。你可以使用@PreDestroy (Spring注解)来实现这一点。您可以使用字段来存储所有需要写入的项。在predestroy函数上,你写你自己的东西。
private List<YourItem> items = new ArrayList<>();
@Override
public void write(argument here) {
items.addAll(YourItem);
}
@PreDestroy
public void teardown() {
// do the write for all items
}https://stackoverflow.com/questions/43244268
复制相似问题