Spring Batch uses 'Chunk Oriented' processing style. (Not just chunk read or write, full process including read, process and write)
Chunk oriented processing refers to
- Read an item using ItemReader (Single Item)
- Process it using ItemProcessor, and aggregate the result (Result List is updated one by one).
- Once the commit interval is reached, the entire aggregated result (Result List) is written out using ItemWriter and then the transaction is committed.
Here is the code representation from SpringBatch doc
List items = new Arraylist();
for(int i = 0; i < commitInterval; i++){
Object item = itemReader.read()
Object processedItem = itemProcessor.process(item);
items.add(processedItem);
}
itemWriter.write(items);
As you said, if you need your reader to return multiple Items, make it a List. And if your processor also returns a List. Finally, your Writer will get a List of List.
Here is the code representation of the new case
List<List<Object>> resultList = new Arraylist<List<Object>>();
for(int i = 0; i < commitInterval; i++){
List<Object> items = itemReader.read()
List<Object> processedItems = itemProcessor.process(items);
resultList.add(processedItems);
}
itemWriter.write(resultList);