title: Custom AllWindowFunction class members
body: <p>I have a custom <code>AllWindowFunction</code> class which has a class member responsible for database inserts. The connection to the database is persistent and opens during construction.</p>
  
  <p>The problem is, that the <code>AllWindowFunction</code> instance that creates/opens the connection isn't the same that gets called on apply event. Workaround for this is a static member, but I would like to know if that is the only workaround?</p>
  
  <p>Example code:</p>
  
  <pre><code>public class CustomWindowFunction implements AllWindowFunction&lt;String, String, TimeWindow&gt; {
  
      private static Connection database;
  
      CustomWindowFunction() {
          database = new Connection();
      }
  
      @Override
      public void apply(TimeWindow timeWindow, Iterable&lt;String&gt; trades, Collector&lt;String&gt; out) {
          // process data
          database.save(data);
          out.collect(data.toString());
      }
  }
  </code></pre>
  
  <p>I couldn't find anything regarding this mechanism, all I know is that object ID from constructor differs from object ID called from <code>apply</code>. </p>