code: public JobExecution completeNewJobWithRestart(String jobXMLName, Properties jobParameters, int restartAttempts) throws IllegalStateException {
          long executionId = jobOp.start(jobXMLName, jobParameters);
          JobExecution jobExec = waitForFinish(executionId);
  
          if (jobExec.getBatchStatus().equals(BatchStatus.FAILED)) {
  
              for (int i = 0; i < restartAttempts; i++) {
                  jobParameters.put("restartCount", Integer.toString(i + 1));
  
                  executionId = jobOp.restart(executionId, jobParameters);
                  jobExec = waitForFinish(executionId);
  
                  if (jobExec.getBatchStatus().equals(BatchStatus.COMPLETED)) {
                      logger.finer("Job " + executionId + " successfully completed.");
                      return jobExec;
                  }
              }
  
              throw new IllegalStateException("Job " + executionId + " failed to complete within the allowed number of restarts (" + restartAttempts + ")."
                                              + " Last execution status is: " + jobExec.getBatchStatus());
  
          } else {
              throw new IllegalStateException("Job " + executionId + " expected to fail and be restartable, but status is: " + jobExec.getBatchStatus());
          }
      }
docs: Wait for {@code JobWaiter#timeout} seconds for BOTH of:
  
  1) BatchStatus to be one of: STOPPED ,FAILED , COMPLETED, ABANDONED
  AND
  2) exitStatus to be non-null
  
  The job is expected to fail on the first attempt, and then a number of restarts up to the
  restartAttempts parameter will be tried. The job may complete before that many restarts
  are attempted.
  
  Returns JobExecution if it ends in <b>COMPLETED</b> status, otherwise throws
  <b>IllegalStateException</b>
  
  @param jobXMLName
  @param jobParameters
  @param restartAttempts
  @return JobExecution (for successfully completing job)
  @throws IllegalStateException