0

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?

  • Why would you need an `ItemStreamReader` for that, your reader is already flawed (imho) and using an `ItemStreamReader` doesn't make it suddenly right. – M. Deinum Jan 11 '23 at 07:11
  • @M.Deinum I appreciate about this comment. You reminded to me important thing i missed. Both open, update methods and constructor must not be used in reading data, but read method. The read method I need to add pagable feature in my read method in my class implemented ItemReader interface – Companion Cube Jan 11 '23 at 08:07
  • Why not using one of the paging item readers provided out of the box by Spring Batch? Did you find any limitation in those built-in readers? – Mahmoud Ben Hassine Jan 11 '23 at 14:36

1 Answers1

0

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.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • I appreciate about this answer. I knew about AbstractPagingItemReader, but I didn't know how to extend these abstracted implementations. I decided too hasty and i have no degree of understanding about batch process. Becaus it's my first batch process in my life. Again, I appreciate you – Companion Cube Jan 12 '23 at 09:46