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

ManagedScheduledExecutorService unexpectedly executes tasks multiple times

XMLWordPrintable

      A ManagedScheduledExecutorService unexpectedly executes tasks multiple times.

      standalone.xml:

      <managed-scheduled-executor-service name="default" jndi-name="java:jboss/ee/concurrency/scheduler/default" context-service="default" hung-task-termination-period="0" hung-task-threshold="60000" keepalive-time="3000"/>
      

      Reproducer app:

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

      The following log is printed.

      Please notice the "duplicate" executions at 11:33:50.

      Apparently the internal compution of the next execution sometimes returns the same value as for the prevoius execution (see log above).

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

                Created:
                Updated:
                Resolved: