3 Replies Latest reply on Apr 2, 2014 9:07 AM by Eduardo Martins

    Bug in JSR 239 Concurrency impl?

    Sueleyman Vurucu Expert

      I'm playing with the Concurrency API aka JSR 239 with wildfly 8.0.0.Final


      For that I'm injecting a excecutor service with


        private  ManagedExecutorService executorService;


      But if I'll excecute the method executorService.isTerminated() then wildfly thorws the exception shown below:


      at io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:58) [undertow-websockets-jsr-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$AnnotatedEndpointFrameHandler$5.run(AnnotatedEndpoint.java:299) [undertow-websockets-jsr-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.websockets.jsr.ServerWebSocketContainer$1.run(ServerWebSocketContainer.java:230) [undertow-websockets-jsr-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:49) [undertow-websockets-jsr-1.0.0.Final.jar:1.0.0.Final]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
          at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
      Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_25]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_25]
          at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_25]
          at io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:54) [undertow-websockets-jsr-1.0.0.Final.jar:1.0.0.Final]
          ... 6 more
      Caused by: java.lang.IllegalStateException: Lifecycle operation not supported
          at org.glassfish.enterprise.concurrent.AbstractManagedExecutorServiceAdapter.isTerminated(AbstractManagedExecutorServiceAdapter.java:73) [javax.enterprise.concurrent-1.0.jar:]
          at com.siemag.base.web.frontend.controller.WMSManagementController.refresh(WMSManagementController.java:176) [classes:]
          at com.siemag.base.web.frontend.controller.WMSManagementController$PLCSocketDataClientEndpoint.onMessage(WMSManagementController.java:64) [classes:]
          ... 11 more


      As I can see there are two implentations

      1. org.glassfish.enterprise.concurrent.AbstractManagedExecutorServiceAdapter

      2. org.glassfish.enterprise.concurrent.AbstractManagedExecutorService


      The @Resource Lookup gives me always an instance of the apapter class. Why?? What am I doing wrong?

        • 1. Re: Bug in JSR 239 Concurrency impl?
          Eduardo Martins Apprentice

          That's an expected exception, JSR 236 executors are managed by the server, i.e. apps are not allowed to use lifecycle related methods. WildFly uses some of Java EE 7 RI code wrt JSR 236, and that adapter class is responsible for limiting access to the underlying executor implementation lifecycle related methods.

          • 2. Re: Bug in JSR 239 Concurrency impl?
            Sueleyman Vurucu Expert

            And how can I determine the state of a thread in a pool?

            • 3. Re: Bug in JSR 239 Concurrency impl?
              Eduardo Martins Apprentice

              Apps don't manage the executors, it makes no sense for apps to look up for such state. For instance, and that's the case for WildFly default instance, apps may share a single executor instance.


              What you can monitor, since that gives app scoped feedback, is task execution state, either by the well know Future & co interfaces, or by making your task implement ManagedTask and provide a ManagedTaskListener there.


              Thread related feedback is also available if you cast the Thread to ManagedThread, but using an executor you don't manage threads, that's useful only for direct ManagedThreadFactory usages.


              PS: ExecutorService#isTerminated() would never provide what you were looking for, according to javadoc: "Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first."