还有其他方法可以使Spring批处理作业执行=已停止。除了jobOperatot.stop(执行ID)。我现在在开发环境中。这需要更多时间。当我调用stop方法时,BATCH_JOB_EXECUTION.STATUS移至“ STOPPING”,并且40分钟后,它仍然处于相同状态,并且作业执行没有停止。
在数据库中手动将BATCH_STEP_EXECUTION.STATUS的状态更改为FAILED,然后重新启动作业,然后重新启动作业。
public <T> T restartJob(JobInputs jobInputs)
throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
try {
if (CommonUtils.isNullOrEmpty(jobInputs.getJobName())) {
List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobInputs.getJobName(), 0, 1);
jobInstance = jobInstances.get(0);
} else
jobInstance = jobExplorer.getJobInstance(jobInputs.getJobID());
List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
if (CollectionUtils.isNotEmpty(jobExecutions)) {
JobExecution execution = jobExecutions.get(0);
if (!execution.getStatus().equals(BatchStatus.FAILED)
|| !execution.getStatus().equals(BatchStatus.STOPPED)) {
execution.setEndTime(new Date());
execution.setStatus(BatchStatus.FAILED);
execution.setExitStatus(ExitStatus.UNKNOWN);
// execution.setVersion(execution.getVersion() + 1);
jobRepository.update(execution);
System.out.println("jobInstanceID:" + jobInstance.getInstanceId() + " Exec ID for "
+ execution.getId() + " job:" + jobInputs.getJobName());
}
executionID = jobOperator.restart(execution.getId());
}
} catch (Exception e1) {
e1.printStackTrace();
}
return executionID;
}