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

十年热恋 提交于 2021-02-10 14:32:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!