1 Reply Latest reply on Jun 4, 2010 3:34 PM by jaikiran pai

    @Asynchronous problem

    Mike McCormick Newbie

      Hello,

       


      I'm using the @Asynchronous annotation for a method on a stateless session bean and it is "blocking" as if the annotaion had not been applied. I have read the documentation and I think I am using it correctly.

       


      Any suggestions on how to make this work?

       


      Windows XP SP3

       

      Java 1.6.0_20-b02

       

      jboss-6.0.0.M3 running in "all" configuration

       


      Actual Results:
      runAysncTest 1
      asyncMethod 1
      runAysncTest 2

       


      Expected Results:
      runAysncTest 1
      runAysncTest 2
      asyncMethod 1

       

      package test;
      public interface AsyncTest {
          public void asyncMethod();    
      }

       

      package test;
      
      import javax.ejb.Asynchronous;
      import javax.ejb.Local;
      import javax.ejb.Stateless;
      
      @Local
      @Stateless
      public class AsyncTestBean implements AsyncTest {
          
          @Asynchronous
          @Override
          public void asyncMethod() {
              //Do something for 5 seconds
              try {
                  for (int i = 0; i < 50; i++) {
                      Thread.sleep(100);
                  }
              }
              catch (InterruptedException e) {
                  e.printStackTrace();
              }
              
              System.out.println("asyncMethod 1");
          }
          
      }
      

       

      package test;
      
      public interface Tester {
      
          public void runAysncTest();
          
      }
      

       

       

       

      package test;
      
      import javax.annotation.PostConstruct;
      import javax.ejb.EJB;
      import javax.ejb.Singleton;
      import javax.ejb.Startup;
      
      @Startup
      @Singleton
      public class TesterBean implements Tester {
          
          @EJB
          private AsyncTest asyncTest;
      
          @Override
          @PostConstruct
          public void runAysncTest() {
              System.out.println("runAysncTest 1");
              asyncTest.asyncMethod();
              System.out.println("runAysncTest 2");
          }
      
      }