title: how to recover spring batch jobs after the server down time
body: <p>The question is regarding to the auto-recovery strategy of the batch jobs.
  Saying the server was shut down due to unknown reasons when there were several jobs running (with status "STARTED" and null end time). How can we recover all these jobs when we start up the server again.</p>
  
  <p>In my situation, I wrote my own job launcher to receive requests and save them into the DB queue. Then I run my own job scheduler to poll the requests from the DB and execute the jobs.
  In order to change these jobs' status from "STARTED" to "STARTING" in order to be picked up by my scheduler again, my current tries contain:</p>
  
  <ol>
  <li><p>because spring batch cannot restart "STARTED" jobs, and even the job is restartable, spring batch will create a new job execution under the same job instance. Hence, if I can restart the job, the origin job id needs to be changed. But we I tried to use the job operator to stop the job with "STARTED" status, and then to restart it again, I failed. Why doesn't this work?</p>
  
  <blockquote>
    <p>jobOperator.stop(jobId);
    jobOperator.restart(jobId);</p>
  </blockquote></li>
  <li><p>I also failed to use the job repository to update the job execution status from "STARTED" to "STARTING". </p>
  
  <blockquote>
    <p>jobExecution.setStatus(BatchStatus.STARTED);
    jobRepository.update(jobExecution);</p>
  </blockquote></li>
  </ol>
  
  <p>Any thoughts of achieving this would be appreciated!</p>