title: Spring Batch : custom ItemReader
body: <p>I have a Spring Batch project with a simple custom reader and writer. When i run the code i end up with an endeless loop printing the first item "item 1". What am i doing wrong? </p>
  
  <p>Here is my code:</p>
  
  <p><strong>Reader.java</strong></p>
  
  <pre><code>public class Reader implements ItemReader&lt;SimpleItem&gt; {
  
  
  public SimpleItem read() throws Exception, UnexpectedInputException, ParseException {
      if (getIterator().hasNext()) {
          return getIterator().next();
      }
      return null;
  }
  
  public Iterator&lt;SimpleItem&gt; getIterator() {
      List&lt;SimpleItem&gt; list = new ArrayList();
      list.add(new SimpleItem("item 1"));
      list.add(new SimpleItem("item 2"));
      return list.iterator();
  }
  
  }
  </code></pre>
  
  <p><strong>Writer.java</strong></p>
  
  <pre><code>public class Writer implements ItemWriter&lt;SimpleItem&gt; {
  @Override
  public void write(List&lt;? extends SimpleItem&gt; list) throws Exception {
      for(SimpleItem item : list) {
          System.out.println(item.getName()); // this prints item 1 endelessly
      }
  }
  }
  </code></pre>