本文介绍了无论如何,要避免使用Spring Batch两次处理同一文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事3个步骤的Spring Batch项目.首先,它将需要的文本文件从ftp下载到本地,然后进行处理,最后每10分钟删除本地目录中的文件.每隔10分钟,FTP中就会加载一个新文件.如果FTP中出现问题并且不加载新文件怎么办?然后,Spring Batch项目下载相同的文件并再次处理.所以我的问题是,如何避免Spring Batch两次处理同一文件?

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?

我已经使用Apache公共库从FTP下载文件.而且我正在使用MultiResourceItemReader在每次运行时提取2个文本文件.

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

推荐答案

我会将文件名用作作业参数.这将为每个文件创建一个作业实例.

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

现在,由于Spring Batch阻止一次运行同一作业实例完成一次,因此每个文件将仅处理一次,并且您可以避免在设计上对同一文件进行两次处理.

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.

这篇关于无论如何,要避免使用Spring Batch两次处理同一文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:34