Home > Net >  some questions about purpose of both ItemStreamReader and ItemStreamWriter in Spring Batch
some questions about purpose of both ItemStreamReader and ItemStreamWriter in Spring Batch

Time:01-13

I'm studying about Spring Batch.

I'm using ItemReader and ItemWriter in my Spring Batch Project.

However, my project's the biggest problem is that all data reading logic is in constructor without paging.

I thought it's so unusual and improper usage.

So I read Spring Batch Documentations, and I found ItemStreamReader, ItemStreamWriter.

I thought it may be useful of improving my project that data reading logic moves to open and update methods with paging.

In order to add paging feature.

However, Document said about only Execution Context.

So I'm not sure that data reading logic in open or update with paging is proper.

Is it okay if I use open, update methods to read paged data?

CodePudding user response:

open / close methods in ItemStream will only be called once to initialize/dispose any resources used by the reader, so they are not suitable to read pages.

I would recommend to use one of the provided paging item readers, or extend them if necessary (see AbstractPagingItemReader and AbstractPaginatedDataItemReader) rather creating a paging item reader from scratch.

  • Related