3 Replies Latest reply on Jan 31, 2012 5:01 PM by Sueleyman Vurucu

    @Asynchronous call for @Stateful

    Sueleyman Vurucu Expert

      Hi Friends,

       

      I have a problem with the @Asynchronous method call on satefull beans. If my bean is stateless  and my asynchronous method computes long time then the container will create a new instance on next call from the client right ?

       

      So I have a Singletonbean which hold references on some Statefull beans. When I call an asynchronous methods of my statefull beans in a sequence then the first computation blocks the rest.

       

      What I assume is that the bean instaces start the comutation parallel. But the real behavior isn't so.

       

      My Sigletom

       

       

      @Startup

      @Singleton

      public class SingletonTest implements SingletonTestLocal {

       

        @EJB

        StateFullTestLocal statefulTest1;

        @EJB

        StateFullTestLocal statefulTest2;

        @EJB

        StateFullTestLocal statefulTest3;

        @EJB

        StateFullTestLocal statefulTest4;

       

        @Resource

        TimerService       timerService;

       

        Logger             lLog = Logger.getLogger(SingletonTest.class);

       

        @SuppressWarnings("unused")

        @PostConstruct

        private void init(){

          createTimer(UUID.randomUUID(), 5000);

        }

       

        @SuppressWarnings("unused")

        @Timeout

        private void timeOut(Timer timer){

          lLog.debug("TIMER START");

          statefulTest1.testAsync();

          statefulTest2.testAsync();

          statefulTest3.testAsync();

          statefulTest4.testAsync();

          lLog.debug("TIMER END");

        }

       

        public void createTimer(UUID beanID, long intervallTime){

          TimerConfig config = new TimerConfig(beanID, false);

          timerService.createIntervalTimer(1000, intervallTime, config);

        }

      }

       

      My Stateful

       

      @Stateful

      @LocalBean

      public class StateFullTest implements StateFullTestLocal {

       

        Logger             log = Logger.getLogger(StateFullTest.class); ;

       

        @EJB

        SingletonTestLocal singletonTest;

       

        @PostConstruct

        public void init(){

          log.debug("PostConstruct");

        }

       

        @Override

        @Asynchronous

        public void testAsync(){

          log.info("Start " + hashCode());

          while (true) {

       

          }

       

      }

       

      My Consoleoutput

       

      13:11:12,802 DEBUG [StateFullTest]  PostConstruct

      13:11:12,802 DEBUG [StateFullTest] PostConstruct

      13:11:12,802 DEBUG [StateFullTest] PostConstruct

      13:11:12,802 DEBUG [StateFullTest] PostConstruct

      13:11:13,880 DEBUG [SingletonTest] TIMER START

      13:11:13,911 DEBUG [SingletonTest] TIMER END

      13:11:13,927 INFO  [StateFullTest]  Start 29639543

       

      The other instances are not triggerd.

       

      So what do I wrong ??

        • 1. Re: @Asynchronous call for @Stateful
          Sueleyman Vurucu Expert

          Hi it's me again,

           

          I tested the example above under jboss 6.1.0.final so I deployed the same EAR in jboss 7.1.0 CR1b and see consoleoutput

           

          13:21:20,450 INFO  [StateFullTest] (pool-9-thread-4) Start 21340825

          13:21:20,450 INFO  [StateFullTest] (pool-9-thread-2) Start 14751062

          13:21:20,450 INFO  [StateFullTest] (pool-9-thread-5) Start 11925707

          13:21:20,450 INFO  [StateFullTest] (pool-9-thread-3) Start 15553660

          13:21:29,450 INFO  [StateFullTest] (pool-9-thread-4) End 21340825

          13:21:29,450 INFO  [StateFullTest] (pool-9-thread-2) End 14751062

          13:21:29,450 INFO  [StateFullTest] (pool-9-thread-5) End 11925707

          13:21:29,450 INFO  [StateFullTest] (pool-9-thread-3) End 15553660

          13:21:30,450 INFO  [StateFullTest] (pool-9-thread-7) Start 14751062

          13:21:30,450 INFO  [StateFullTest] (pool-9-thread-10) Start 11925707

          13:21:30,450 INFO  [StateFullTest] (pool-9-thread-9) Start 21340825

          13:21:30,450 INFO  [StateFullTest] (pool-9-thread-8) Start 15553660

          13:21:39,451 INFO  [StateFullTest] (pool-9-thread-8) End 15553660

          13:21:39,451 INFO  [StateFullTest] (pool-9-thread-7) End 14751062

          13:21:39,451 INFO  [StateFullTest] (pool-9-thread-10) End 11925707

          13:21:39,451 INFO  [StateFullTest] (pool-9-thread-9) End 21340825

          13:21:40,451 INFO  [StateFullTest] (pool-9-thread-4) Start 14751062

          13:21:40,451 INFO  [StateFullTest] (pool-9-thread-5) Start 15553660

          13:21:40,451 INFO  [StateFullTest] (pool-9-thread-2) Start 21340825

          13:21:40,451 INFO  [StateFullTest] (pool-9-thread-3) Start 11925707

           

          I used Thread.sleep instead of while(true) of course .

           

          Can I assume that this behaviour was a bug in Jboss 6.1.0 ??

          • 2. Re: @Asynchronous call for @Stateful
            Wolf-Dieter Fink Master

            Do you test the sleep loop also with 6.1 ? Otherwise I'm not sure whether you see the log if the empty while() is running.

             

            It might be a bug in 6.1 but I suppose it will not be fixed because of 7.x release is near

            • 3. Re: @Asynchronous call for @Stateful
              Sueleyman Vurucu Expert

              Wolf-Dieter Fink schrieb:

               

              Otherwise I'm not sure whether you see the log if the empty while() is running.

               

              Of course not. .

               

              I'll see only

              13:21:20,450 INFO  [StateFullTest] (pool-9-thread-4) Start 21340825

              13:21:20,450 INFO  [StateFullTest] (pool-9-thread-2) Start 14751062

              13:21:20,450 INFO  [StateFullTest] (pool-9-thread-5) Start 11925707

              13:21:20,450 INFO  [StateFullTest] (pool-9-thread-3) Start 15553660

               

              My stateles instance begin parallel working. In Jboss 6.1 is that call serialized. In Jboss 7.1 it works parallel.