Is there anyway to avoid processing same file twice with Spring Batch?

只谈情不闲聊 提交于 2020-04-30 06:26:55

问题


I am working on the 3 steps Spring Batch project. Firstly, it downloads needed text files from ftp to local, then process it, and finally delete files in the local directory every 10 minutes. And every 10 minutes there are new files loaded in the FTP. What if there emerge some problem in the FTP and it does not load new files? Then Spring Batch project download same file and process it again. So my question is that how can avoid Spring Batch to process same file twice?

Edit: I have used Apache common library to download files from FTP. And I am using MultiResourceItemReader to pull 2 text files at each run.


回答1:


I would use the file name as a job parameter. This will create a job instance for each file.

Now since Spring Batch prevents running the same job instance to completion more than once, then each file would be processed only once and you could avoid processing the same file twice by design.



来源:https://stackoverflow.com/questions/61383694/is-there-anyway-to-avoid-processing-same-file-twice-with-spring-batch

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