title: Apache Flink Process Function state is not holding the state
body: <p>I am writing some code for a <code>processElement</code> function in Apache Flink 1.4:</p>
  <pre><code>public class ProcessFunctionClass extends ProcessFunction&lt;Tuple2&lt;String, String&gt;, Tuple2&lt;String, String&gt;&gt;{
  
      private ListState&lt;String&gt; listState;
  
      public void processElement(Tuple2&lt;String, String&gt; tuple2,  Context context, Collector&lt;Tuple2&lt;String, String&gt;&gt; collector) {
  
          // if the state is empty, start a timer
          if (listState.get().iterator().hasNext() == false)
              context.timerService().registerEventTimeTimer(10000);
  
          listState.add(&quot;someStringToBeStored&quot;);
  
          // ...
      }
  
  }
  </code></pre>
  <p>I have this function for when the timer expires:</p>
  <pre><code>public void onTimer(long timestamp, OnTimerContext ctx, Collector&lt;Tuple2&lt;String, String&gt;&gt; out) throws Exception {
      Iterable&lt;String&gt; strings = listState.get();
      int cnt = 0;
      int totalLength = 0;
      Iterator&lt;String&gt; it = strings.iterator();
      while (it.hasNext()) {
          cnt++;
          totalLength += it.next().length();
      }
      LOGGER.info(&quot;cnt is:&quot; + cnt);
      LOGGER.info(&quot;totalLength is:&quot; + totalLength);
  
      // clearing the state
      listState.clear();
  }
  </code></pre>
  <p>However every time I run the application, the value of <code>cnt</code> is always 1, and the value of <code>totalLength</code> is the length of the particular string that has been processed at that time. It looks like the state is not kept in the system. From this code is it clear what I am doing wrong here?</p>