【发布时间】:2017-06-27 18:47:30
【问题描述】:
我是 Spring Batch 的新手,我正在尝试在批处理之后使用 SystemCommandTasklet 作为第二步运行 linux 排序命令。但是,在对较大的文件进行排序时会抛出 NullPointerException(这需要一些时间,大约 250 MB)。看起来 SystemCommandTasklet 无法在 beforeStep() 中初始化 StepExecution 并引发错误。有人可以检查我的配置并让我知道我是否缺少某些导致此问题的配置吗?
BatchConfig.java
@Bean
public Job job() throws Exception {
return jobs.get("job")
.incrementer(new RunIdIncrementer())
.flow(step1()).on("FAILED").fail().on("COMPLETED").to(step2())
.end()
.build();
}
@Bean
public Step step1() {
return steps.get("step1")
.<FileEntry,FileEntry>chunk(100)
.reader(reader()).faultTolerant().skipLimit(MAX_SKIP_LIMIT).skip(FlatFileParseException.class)
.processor(new Processor())
.writer(compositeWriter()).stream(outputwriter()).stream(rejectwriter())
.listener(new CustomStepExecutionListener())
.build();
}
@Bean
public Step step2() throws Exception {
return steps.get("step2")
.tasklet(sortingTasklet())
.build();
}
@Bean
@StepScope
public Tasklet sortingTasklet() throws Exception {
SystemCommandTasklet tasklet = new SystemCommandTasklet();
logger.debug("Sorting File : " + getOutputFileName());
tasklet.setCommand(new String("sort " + getOutputFileName() + " -d -s -t \001 -k1,1 -o " + getOutputFileName() + ".sorted "));
tasklet.setTimeout(600000l);
return tasklet;
}
这里是 SystemCommandTasklet 的 SpringBatch 源代码的链接,它在第 131 行抛出 NullPointerException。
https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java
【问题讨论】:
标签: spring spring-boot spring-batch