title: Cancel timer in lifecycle callback of singleton bean
body: <p>I have an Java EE project running Wildfly 10.1 Final.</p>
  
  <p>I am creating some timers programmatically using <code>javax.ejb.TimerService</code> like this:</p>
  
  <pre><code>timerService.createTimer(new Date(), null);
  </code></pre>
  
  <p>And now, I am trying to cancel those timers the next time the project is deployed, because they are still there every time I re-deploy the project, or restart the server.</p>
  
  <p>I tried to use a <code>Singleton</code> <code>Startup</code> bean for that, like this:</p>
  
  <pre><code>@Startup
  @Singleton
  public class TimerKiller {
  
      @PostConstruct
      public void killTimers() {
          timerService.getAllTimers().forEach(timer -&gt; timer.cancel());
      }
  
      @Resource
      TimerService timerService;
  }
  </code></pre>
  
  <p>But, I get an exception:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: WFLYEJB0325: Cannot invoke timer
    service methods in lifecycle callback of non-singleton beans</p>
  </blockquote>
  
  <p>This is the last exception in the stack trace (the last Caused By).</p>
  
  <p>I can't seem to understand what does this mean. I tried googling but nothing comes up. </p>