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

ManagedScheduledExecutorService should be only available after server is ready

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 17.0.1.Final
    • None
    • Concurrency Utilities
    • None

    Description

      I use a ManagedScheduledExecutorService to execute tasks periodically:

      @Startup
      @Singleton
      public class TaskScheduler {
      
          @Resource
          ManagedScheduledExecutorService executorService;
      
          @PostConstruct
          public void init() {
              executorService.scheduleAtFixedRate(this::task, 0, 5, TimeUnit.SECONDS);
          }
      
          public void task() {
              System.out.println("long running task:" + LocalTime.now());
          }
      }
      

      Wildfly throws a few exceptions as long as server is not fully initiated and in "suspend"-mode:

      12:44:12,715 ERROR [org.jboss.as.ee] (EE-ManagedScheduledExecutorService-default-Thread-3) WFLYEE0110: Failed to run scheduled task: java.lang.IllegalStateException: WFLYEE0111: Cannot run scheduled task my.Task$$Lambda$1041/0x000000080240a040@5ee966ec as container is suspended
      	at org.jboss.as.ee@17.0.1.Final//org.jboss.as.ee.concurrent.ControlPointUtils$ControlledScheduledRunnable.run(ControlPointUtils.java:164)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
      	at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.internal.ManagedScheduledThreadPoolExecutor$ManagedScheduledFutureTask.access$201(ManagedScheduledThreadPoolExecutor.java:383)
      	at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.internal.ManagedScheduledThreadPoolExecutor$ManagedScheduledFutureTask.run(ManagedScheduledThreadPoolExecutor.java:534)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:835)
      	at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:250)
      

      I use ManagedScheduledExecutorService instead of ScheduledExecutorService in JEE because, ManagedScheduledExecutorService should be managed by JEE. Hence, the server should also manage and guarantee not to fire the executorService until the server is ready (and EJBs are available).

      Attachments

        Issue Links

          Activity

            People

              emartins@redhat.com Eduardo Martins
              nimo22 nimo stephan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: