Java Spring批处理作业不会在最后一步后结束
我的Spring批处理作业设置如下:Java Spring批处理作业不会在最后一步后结束,java,spring-batch,Java,Spring Batch,我的Spring批处理作业设置如下: @Bean Job myJob(JobBuilderFactory jobBuilderFactory, @Qualifier("stepA") Step stepA, @Qualifier("s"tepB) Step stepB) { return jobBuilderFactory.get("myJob") .incrementer(new Run
@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);
}
@Autowired
JobLauncher(@Qualifier(“myJob”)作业作业,JobLauncher JobLauncher){
这个工作=工作;
this.jobLauncher=jobLauncher;
}
@计划(固定延迟=5000)
void launcher()引发JobParametersInvalidException、JobExecutionAlreadyRunningException、JobRestartException、JobInstanceAlreadyCompleteException{
run(job,newExecution());
}
私有作业参数newExecution(){
映射参数=新的HashMap();
this.dateTime=新的日期时间(DateTimeZone.UTC);
this.dateTimeString=this.dateTime.toString(ISODateTimeFormat.dateTime());
JobParameter=新的JobParameter(this.dateTimeString);
parameters.put(“currentTime”,参数);
返回新的作业参数(参数);
}
如您所见,我的作业计划每5秒启动一次。
但是,在第一次发射之后,它并没有结束;它将继续执行下一次执行。
这工作就像一个循环。我希望它在5秒钟后停止并重新启动。我没有注意到读卡器在完成时需要返回null。问题已解决。您也可以使用System.exit(0);在主类的末尾,它将终止JVM,从而终止批处理