Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-20744

ManagedScheduledExecutorService does not stop scheduled tasks after undeployment

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 36.0.1.Final
    • Concurrency Utilities
    • None
    • ---
    • ---

      We noticed that the undeployment of a WAR with a scheduled timer does not stop the timer (the timer still runs after undeplyoment) and after a new deplyoment the timer generally runs twice and so on.

      import jakarta.annotation.Resource;
      import jakarta.enterprise.concurrent.CronTrigger;
      import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
      import jakarta.enterprise.context.ApplicationScoped;
      import jakarta.enterprise.event.Observes;
      import jakarta.enterprise.event.Startup;
      
      import java.time.ZoneId;
      
      @ApplicationScoped
      public class DummyBean {
      
          @Resource(mappedName = "java:jboss/ee/concurrency/scheduler/default")
          ManagedScheduledExecutorService executorService;
      
          public DummyBean() {
          }
      
          private void onStart(@Observes Startup startup) {
              executorService.schedule(() -> something(), new CronTrigger(ZoneId.systemDefault()).hours("*").minutes("*").seconds("*/10"));
          }
      
          private void something() {
              System.out.println("something " + System.currentTimeMillis());
          }
      
      }
      

      This apparently is a spec violation: https://jakarta.ee/specifications/concurrency/3.1/jakarta-concurrency-spec-3.1#jakarta-ee-product-provider-requirements-3

      3. All tasks submitted to an executor must not run if task’s component is not started.
      

              emartins@redhat.com Eduardo Martins
              beth-soptim Thomas Beckers
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: