Spring-Batch作业不会在最后一步之后结束

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

我的Spring-Batch作业设置如下:

@Bean
Job myJob(JobBuilderFactory jobBuilderFactory,
                   @Qualifier("stepA") Step stepA,
                   @Qualifier("s"tepB) Step stepB) {
    return jobBuilderFactory.get("myJob")
            .incrementer(new RunIdIncrementer())
            .start(stepA)
            .next(stepB)
            .build();
}

这是我的发射器:

@Autowired
JobLauncher(@Qualifier("myJob") Job job, JobLauncher jobLauncher) {
    this.job = job;
    this.jobLauncher = jobLauncher;
}

@Scheduled(fixedDelay=5000)
void launcher() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
    jobLauncher.run(job, newExecution());
}

private JobParameters newExecution() {
    Map<String, JobParameter> parameters = new HashMap<>();

    this.dateTime = new DateTime(DateTimeZone.UTC);
    this.dateTimeString = this.dateTime.toString(ISODateTimeFormat.dateTime());
    JobParameter parameter = new JobParameter(this.dateTimeString);
    parameters.put("currentTime", parameter);

    return new JobParameters(parameters);
}

如您所见,我的工作计划每5秒启动一次。但是,首次发布后,它并没有结束;它继续下一次执行。这项工作就像在一个循环中。我希望它在5秒后停止并重新启动。

java spring-batch
1个回答
0
投票

我错过了读者完成后需要返回null。问题解决了。

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