
Originally Posted by
arno
if you job runs daily, you should indeed use a job parameters for the day
OK, clear. I need to add one parameter, which is dependant on the day of start.
I hope, the framework could provide the method like restartOrStartNewJob(Job job) like this:
Code:
void restartOrStartNewJob(Job job) {
JobParameters jobParameters = null;
List<JobInstance> lastInstances = jobExplorer.getJobInstances(job.getJobName(), 0, 1);
if (!CollectionUtils.isEmpty(lastInstances)) {
// Try to restart the last execution:
jobParameters = lastInstances.get(0).getJobParameters();
}
if (jobParameters == null) {
// Try to start a new instance:
jobParameters = job.getJobParametersIncrementer().getNext(createDefaultJobParameters());
}
try {
logger.info("Attempting to re-launch job with parameters " + jobParameters);
Long executionId;
try {
executionId = jobLauncher.run(job, jobParameters).getId();
}
catch (JobInstanceAlreadyCompleteException e) {
jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
logger.info("Attempting to start new job with parameters " + jobParameters);
executionId = jobLauncher.run(job, jobParameters).getId();
}
...
}
catch (JobInstanceAlreadyCompleteException e) {
// This situation should never happen, as we have taken steps to increment the parameters:
...
}
catch (JobExecutionAlreadyRunningException e) {
...
}
catch (JobRestartException e) {
...
}
catch (JobParametersInvalidException e) {
...
}
}
Thanks for the link. After reading the docu again, I understand the basics better 
2eparchas:

Originally Posted by
eparchas
How do you resume job executions that have started but are not completed nor failed nor stopped because the server for some reason went down? How is it possible to resume these cases and have the job pickup where it left-off?
I have a kind of ugly solution, which I put into the initial post. I would like to hear from Batch core developers, if resetStaleJob() above looks good. eparchas, you can use it as is – it works absolutely fine for me.