问题
Is there a way to limit the maximum number of processing records in a job of Spring Batch?
I need to have a configuration by which I could control the maximum number of records that can be processed by a job.
The job is reading from Database using a Stored Procedure, I could limit the maximum number of fetched rows in the Procedure itself, but I am looking for any features provided in Spring Batch for that and I am not able to find it yet.
回答1:
Write a custom ItemReader
holds record count and return null
('stop reading') when the limit is reached.
Store variable used to count records into step-execution context.
Remember to let your custom ItemReader
implements ItemStream
: in this manner SB will save/restore record count into/from context automatically.
I hope I was clear, English is not my native language.
来源:https://stackoverflow.com/questions/29091668/is-there-a-way-to-limit-the-maximum-number-of-processing-records-in-a-job-of-spr