title: spring batch Running only one Job Instance at a time and create queue it up
body: <p>Running only on job instance at a time this ok : <a href="https://stackoverflow.com/questions/23193779/spring-batch-restrict-single-instance-of-job-only">Spring batch restrict single instance of job only</a></p>
  
  <pre><code>public class jobMailListener implements JobExecutionListener {
  
  // active JobExecution, used as a lock.
  private JobExecution _active;
  
  
  public void beforeJob(JobExecution jobExecution) {
      // create a lock
      synchronized (jobExecution) {
          if (_active != null &amp;&amp; _active.isRunning()) {
               //***************************//
              // Here create/storage in queue it up ? 
              //****************************//
              jobExecution.stop();
          } else {
              _active = jobExecution;
          }
      }
  }
  
  public void afterJob(JobExecution jobExecution) {
      // release the lock
      synchronized (jobExecution) {
          if (jobExecution == _active) {
              _active = null;
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>&lt;batch:job id="envoiMail" restartable="true"&gt;
      &lt;batch:listeners&gt;&lt;batch:listener ref="jobMailListener"/&gt;
      &lt;batch:step id="prepareData"&gt;...
  </code></pre>
  
  <p>I would not stop the jobs but create a queue.</p>
  
  <p>Can be used spring integration ?</p>
  
  <p>I thought <a href="http://incomplete-code.blogspot.fr/2013/03/spring-batch-running-only-one-job.html#comment-form" rel="nofollow noreferrer">http://incomplete-code.blogspot.fr/2013/03/spring-batch-running-only-one-job.html#comment-form</a>
  But it is not functional.</p>