@Override public JobExecution run(final Job job, final JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
Assert.notNull(job, "The Job must not be null."); Assert.notNull(jobParameters, "The JobParameters must not be null.");
final JobExecution jobExecution;
// 마지막으로 실행된 JobExecution 객체가 있는지 확인한다. JobExecutionlastExecution= jobRepository.getLastJobExecution(job.getName(), jobParameters); if (lastExecution != null) {
// Job Restart 설정을 확인한다. if (!job.isRestartable()) { thrownewJobRestartException("JobInstance already exists and is not restartable"); }
for (StepExecution execution : lastExecution.getStepExecutions()) { BatchStatusstatus= execution.getStatus(); if (status.isRunning() || status == BatchStatus.STOPPING) { thrownewJobExecutionAlreadyRunningException("A job execution for this job is already running: " + lastExecution); } elseif (status == BatchStatus.UNKNOWN) { thrownewJobRestartException( "Cannot restart step [" + execution.getStepName() + "] from UNKNOWN status. " + "The last execution ended with a failure that could not be rolled back, " + "so it may be dangerous to proceed. Manual intervention is probably necessary."); } } }
// JobParamter 에 대한 검증을 진행한다. job.getJobParametersValidator().validate(jobParameters);
@Override publicvoidafterPropertiesSet()throws Exception { Assert.state(jobRepository != null, "A JobRepository has not been set."); if (taskExecutor == null) { logger.info("No TaskExecutor has been set, defaulting to synchronous executor."); taskExecutor = newSyncTaskExecutor(); } } }