title: Spring batch skips records
body: <p>I have a spring batch (3.0.4.RELEASE) job configured to index some records in solr. I'm not experiencing any exceptions and the job responds as completing successfully, however on occasion it is only processing around half of the records in the database. I have configured a <code>JdbcCursorItemReader</code> and custom writer, as shown below.</p>
  
  <pre><code>&lt;batch:job-repository id="jobRepository"
                        data-source="dataSource"
                        transaction-manager="transactionManager"
                        isolation-level-for-create="DEFAULT"
                        table-prefix="BATCH_"
                        max-varchar-length="1000"/&gt;
  
  &lt;bean id="myItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="sql" value="SELECT id FROM my_item ORDER BY id asc"/&gt;
      &lt;property name="rowMapper" ref="myItemIdRowMapper"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"&gt;
      &lt;property name="concurrencyLimit" value="4"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"&gt;
      &lt;property name="jobRepository" ref="jobRepository"/&gt;
      &lt;property name="taskExecutor" ref="taskExecutor"/&gt;
  &lt;/bean&gt;
  
  &lt;batch:job id="myItemIndexJob" restartable="true" job-repository="jobRepository"&gt;
      &lt;batch:listeners&gt;
          &lt;batch:listener ref="executionListener"/&gt;
      &lt;/batch:listeners&gt;
      &lt;batch:step id="myItemSolrIndexStep" allow-start-if-complete="true"&gt;
          &lt;batch:tasklet&gt;
              &lt;batch:chunk reader="myItemReader" writer="myItemSolrWriter" commit-interval="50"/&gt;
          &lt;/batch:tasklet&gt;
      &lt;/batch:step&gt;
  &lt;/batch:job&gt;
  </code></pre>
  
  <p>The row mapper simply returns the id from the query</p>
  
  <pre><code>public final class MyItemRowMapper implements RowMapper&lt;Integer&gt; {
  
      @Override
      public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
          return rs.getInt("id");
      }
  
  }
  </code></pre>
  
  <p>And the writer hands off to a service to index in solr. The writer does not modify MyItem.</p>
  
  <pre><code>public class MyItemSolrWriter implements ItemWriter&lt;Integer&gt; {
  
      @Override
      public void write(List&lt;? extends Integer&gt; myItemIds) throws Exception {
          service.index(Lists.newArrayList(myItemIds));
      }
  }
  </code></pre>
  
  <p>This is the <code>step_execution</code> database entry for the job run which indicates that it hasn't skipped anything and has read only <code>279086</code> rows</p>
  
  <pre><code>|     step_name            | start_time              | end_time                | status    | read_count | filter_count | write_count | read_skip_count | write_skip_count | exit_message |
  | myItemSolrIndexStep      | 2016-05-12 10:07:01.994 | 2016-05-12 10:09:07.303 | COMPLETED | 279086     | 0            | 279086      | 0               | 0                |              |
  </code></pre>
  
  <p>And the <code>step_execution_context</code> database entry indicating that the reader has read <code>573937</code> rows</p>
  
  <pre><code>{"map":[{"entry":[{"string":"JdbcCursorItemReader.read.count","int":573937},{"string":["batch.taskletType","org.springframework.batch.core.step.item.ChunkOrientedTasklet"]},{"string":["batch.stepType","org.springframework.batch.core.step.tasklet.TaskletStep"]}]}]}
  </code></pre>
  
  <p>A subsequent run results in the full <code>573937</code> records being processed, so this only happens intermittently. Any ideas for what might cause it, or methods for debugging the issue?</p>
  
  <p>I can provide more detail if necessary</p>