【问题标题】:Spring batch for processing large processing csv file用于处理大型处理 csv 文件的 Spring Batch
【发布时间】:2018-05-22 03:20:09
【问题描述】:

我有一个 5gb CSV 文件,我正在尝试使用 Spring Batch 处理(读取、处理、将数据发布到 JMS)。记住不要将文件拆分为较小的文件,并且必须处理所有记录,最好的方法是什么? Spring Batch 是否能够在数据从源流式传输时处理和写入数据?有没有办法告诉 Spring Batch 从文件中读取 X 行,处理和写入(提交),然后从文件中获取下 X 行,同时跟踪它已经处理了哪些行

请帮帮我。

【问题讨论】:

    标签: spring-batch


    【解决方案1】:

    是的。这是 Spring Batch 的基本特征。为此使用提交间隔。 建议在这里阅读完整的细节。

    https://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html

    【讨论】:

    • 感谢您回答我的问题。我对小文件做了大文件,我的小文件数量超过 5k。我想应用 10 个线程来处理 5k 个文件。在这里我做了一点,但它一次处理 5k 个文件,而不是 10 个线程处理 5k 个文件。这是我的代码。
    • springframework.org/schema/batch">
    • springframework.org/schema/batch">
    • Multiresource partitioner:Multiresource partitioner:public Map partition(int gridSize) {int index = 0;File directory = new File(outputPath);文件[] fList = directory.listFiles();映射结果 = new HashMap(gridSize); for (File file : fList) { ExecutionContext exContext = new ExecutionContext(); exContext.put(ECDCConstants.THREAD_NAME, "线程" + index); exContext.put(ECDCConstants.OUTPUT_FILE, outputPath + file.getName()); result.put(ECDCConstants.PARTITION + index, exContext);索引++; } }
    猜你喜欢
    • 2012-10-02
    • 2016-06-29
    • 2012-05-23
    • 1970-01-01
    • 2015-02-20
    • 2015-10-10
    • 2018-01-21
    • 2020-04-27
    相关资源
    最近更新 更多