Spring批处理多线程

问题描述 投票:0回答:1

问题陈述:成功完成spring作业后,将无法访问spring批处理分区中设置的ExecutionContext中的数据。

分区代码:

for (String files : fileNameListmatch) {
            ExecutionContext executionContext = new ExecutionContext();
            executionContext.putString("file", files);

            partitionData.put("partition: " + partitionNo, executionContext);
            partitionNo++;
        }

在内部分区代码中,我将文件列表添加到ExecutionContext

JobListener代码:

    @Value("#{stepExecutionContext['file']}") 
    String file;
    @Override
      public void afterJob(JobExecution jobExecution) {
                      for (String file1 : file) {
                                moveCSVFile = Files.move(Paths.get(inputFilePath + "/" + file1 + ".csv"),
                                        Paths.get(archiveFilePath + file1 + ".csv"));
                                moveCTLFile = Files.move(Paths.get(inputFilePath + "/" + file1 + ".ctl"),
                                        Paths.get(archiveFilePath + file1 + ".ctl"));
                        }   
    }

afterJob内部,我试图在工作完成后从ExecutionContext访问文件列表。在ExecutionContext内部获取空。

成功完成工作后,我必须将输入文件移动到另一个文件夹,但是将无法访问文件(在executmentContext中获取null)。工作完成后,我必须将输入文件从一个文件夹移动到另一个文件夹。

multithreading spring-batch
1个回答
0
投票

有两种不同的执行上下文:一种在步骤级别,另一种在作业级别。确保要使用作业范围的作业,因为您要从作业侦听器访问执行上下文。

如果使用范围限定的步骤,则始终可以使用ExecutionContextPromotionListener将键提升到作业执行上下文。有关更多详细信息,请参考Passing Data to Future Steps部分。

© www.soinside.com 2019 - 2024. All rights reserved.