title: How to start a processing time timer in CustomTrigger only on the first element?
body: <p>I'm using GlobalWindow with custom <code>Trigger</code> for my application. As per the requirement, in the Trigger function, I need to start a processing time timer only on the first element in the window. </p>
  
  <p>I tried implementing it using a variable <code>firstEventflag</code>. Like so.</p>
  
  <pre><code>.window(GlobalWindows.create())
  .trigger(new Trigger&lt;ImpactEventObject, GlobalWindow&gt;() {
      Boolean firstEventflag = false;
  
      @Override
      public TriggerResult onElement(ImpactEventObject impactEventObject, long l, GlobalWindow globalWindow, TriggerContext triggerContext) throws Exception {
          if (!firstEventflag) {
              firstEventflag = true;
              triggerContext.registerProcessingTimeTimer(
                  triggerContext.getCurrentProcessingTime() + 20000);
          }
          return TriggerResult.CONTINUE;
      }
  
      @Override
      public TriggerResult onProcessingTime(long l, GlobalWindow globalWindow, TriggerContext triggerContext) throws Exception {
      return TriggerResult.FIRE;
  }
  </code></pre>
  
  <p>But this fails because today I discovered that the variable <code>firstEventflag</code> is not initialized every time a new window is created, it depends on the subtask that is processing the window, meaning different windows can share the same variable <code>firstEventflag</code> rendering this logic effectively useless. Given this, how do I go about solving my problem?</p>