Spring-Batch job does not end after last step

一个人想着一个人 提交于 2019-12-11 14:14:33

问题


My Spring-Batch job is set like that:

@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();
}

And here is my launcher:

@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);
}

As you can see, my job is scheduled to launch every 5 seconds. But, after first launch, it does not end; it goes on the next execution. The job is like in a loop. I would like it to stop and restart after 5 seconds.


回答1:


I missed that readers need to return null when they finish. Problem solved.



来源:https://stackoverflow.com/questions/49094565/spring-batch-job-does-not-end-after-last-step

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!