Debadatta
Debadatta

Reputation: 716

Is there a way to limit the maximum number of processing records in a Job of Spring Batch?

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.

Upvotes: 3

Views: 2202

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18383

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.

Upvotes: 7

Related Questions