title: Simple Spring Batch Job with scheduler: First iteration succeeds. Subsequent iterations fail
body: <p>I tried out Spring Batch with the <strong>Simple Spring Batch Project</strong> provided by STS. I added Spring's scheduling functionality and use PostgreSQL for storing metadata. </p>
  
  <p>I use a simple configuration and an example implementation of ItemReader and ItemWriter, as you can see below. The Job is defined to run every 15 seconds. While everything works well in the first iteration, <strong>reading and writing seems to be skipped</strong> in the subsequent iterations.</p>
  
  <p><em>Here is the job-config:</em> </p>
  
  <pre><code>&lt;batch:job id="job1"&gt;
      &lt;batch:step id="step1"&gt;
          &lt;batch:tasklet start-limit="100" transaction-manager="transactionManager"&gt;
              &lt;batch:chunk reader="reader" writer="writer"
                  commit-interval="1" /&gt;
          &lt;/batch:tasklet&gt;
      &lt;/batch:step&gt;
  &lt;/batch:job&gt;
  
  &lt;!-- Run every 15 seconds --&gt;
  &lt;task:scheduled-tasks&gt;
      &lt;task:scheduled ref="testTask" method="run"
          cron="*/15 * * * * *" /&gt;
  &lt;/task:scheduled-tasks&gt;
  </code></pre>
  
  <p><em>There you can see my reader and writer:</em></p>
  
  <pre><code>@Component("reader")
  public class ExampleItemReader implements ItemReader&lt;String&gt; {
  
      private String[] input = {"Hello world!","Wow!", "Thats","cool!",null};
      private int index = 0;
  
      public String read() throws Exception {
          if (index &lt; input.length) {
              return input[index++];
          }
          else {
              return null;
          }
       }
  }
  
  @Component("writer")
  public class ExampleItemWriter implements ItemWriter&lt;Object&gt; {
  
       public void write(List&lt;? extends Object&gt; data) throws Exception {
             System.out.println("data: " + data);
       }
  }
  </code></pre>
  
  <p><em>And this is the console output for iteration 1 and 2:</em></p>
  
  <pre><code>&lt;Job: [FlowJob: [name=job1]] launched with the following parameters: [{date=Fri Dec 20 17:00:15 CET 2013}]&gt;
  &lt;Job execution starting: JobExecution: id=18, version=0, startTime=null, endTime=null, lastUpdated=Fri Dec 20 17:00:15 CET 2013, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=18, version=0,JobParameters=[{date=Fri Dec 20 17:00:15 CET 2013}], Job=[job1]]&gt;
  &lt;Resuming state=job1.step1 with status=UNKNOWN&gt;
  &lt;Handling state=job1.step1&gt;
  &lt;Executing step: [step1]&gt;
  &lt;Executing: id=18&gt;
  &lt;Starting repeat context.&gt;
  &lt;Repeat operation about to start at count=1&gt;
  &lt;Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@33f487e7&gt;
  &lt;Chunk execution starting: queue size=0&gt;
  &lt;Starting repeat context.&gt;
  &lt;Repeat operation about to start at count=1&gt;
  &lt;Repeat is complete according to policy and result value.&gt;
  &lt;[Hello world!]&gt;
  &lt;Inputs not busy, ended: false&gt;
  &lt;Applying contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]&gt;
  &lt;Saving step execution before commit: StepExecution: id=18, version=1, name=step1, status=STARTED, exitStatus=EXECUTING, readCount=1, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=&gt;
  
  
  ... output of other chunks ommitted ...
  
  
  &lt;Repeat is complete according to policy and result value.&gt;
  &lt;Step execution success: id=18&gt;
  &lt;Step execution complete: StepExecution: id=18, version=7, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=4, filterCount=0, writeCount=4 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=5, rollbackCount=0&gt;
  &lt;Completed state=job1.step1 with status=COMPLETED&gt;
  &lt;Handling state=job1.end1&gt;
  &lt;Completed state=job1.end1 with status=COMPLETED&gt;
  &lt;Job execution complete: JobExecution: id=18, version=1, startTime=Fri Dec 20 17:00:15 CET 2013, endTime=null, lastUpdated=Fri Dec 20 17:00:15 CET 2013, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=18, version=0, JobParameters=[{date=Fri Dec 20 17:00:15 CET 2013}], Job=[job1]]&gt;
  &lt;Job: [FlowJob: [name=job1]] completed with the following parameters: [{date=Fri Dec 20 17:00:15 CET 2013}] and the following status: [COMPLETED]&gt;
  Exit Status : COMPLETED
  </code></pre>
  
  <p>So far i have no clue what could cause that behaviour. I hope anyone of you guys can tell me what to do in order to <strong>make reading and writing take place at any iteration!</strong></p>
  
  <p>Thank you in advance!   </p>
  
  <p>achingfingers</p>