Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why spring batch itemWriter has method write with list of data

I am new in spring batch so maybe I am wrong but I dont understand why write method in itemWriter need list of data:

void write(List<? extends T> items) throws Exception;

If I understand this process first is itemReader which read list of item. In first iteration read first item and so on... Next step is itemProcessor which gets data from itemReader. Then there is some processing and itemProcessor return new class which we want to save somewhere. So last step is itemWriter which get this class which return itemProcessor. So I dont know when itemWriter gets list of data. When I debugging my simple sample project there is still just one item in this list. Please someone explain me it

thx a lot

like image 780
hudi Avatar asked Mar 23 '23 16:03

hudi


1 Answers

The answer is in this sequence diagram from the Spring Batch documentation.

enter image description here

If this is not clear enough, the documentation (again!) explains that Spring uses a chunck oriented processing style:

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.

Actually the Spring Batch documentation is quite good. I would recommend to read it if you are starting with Spring Batch.

like image 196
LaurentG Avatar answered Apr 24 '23 22:04

LaurentG