6 Replies Latest reply on Dec 7, 2011 4:33 PM by zeeman

    Annotation @Asynchronous doesn't work as expected

    netsrac

      Hi,
      I'm having a Seam 3 project (war packaged) in wich i try to process some work asyncronously.
      I read that the EJB Specs doesnt allow to create my own threads because the EJB container has the responsibility for managing these. So I found the @Asynchronous annotation which should process a calles method async. i.e. the control flow would return to the client.


      I have the following Code - a Controller with the method doSomeWork() that is called from the gui:


      @Stateful
      @SessionScoped
      @Named("mycontroller")
      public class MyController {
      
              @Inject
              private AsyncWork async;
              @Inject
              private Credentials credentials;
      ...
      
      public void doSomeWork() {
              async.run(url, bean);
              //further processing
              }
      }



      And my class with the async method:



      @Stateful
      public class AsyncWork{
      
      private String url;
      private Bean bean;
      
      public AsyncWork() {} 
      
      @Asynchronous
              public void run(String url, Bean bean) {
              //do some long processing work
              }
      }



      I did not configure any other files. But I expected that the class AsyncWork is called and while the long processing work is done the client moves on to the called page. But the client waits until the processing is finished.So the @Asyncronous annotation seems to have no effect on my Application.


      What am I doing wrong? Or could it be an EJB Containment Problem. Its a maven project and a selected ear in the pom, but still a war-archive is build.
      Thanks for any help!



        • 1. Re: Annotation @Asynchronous doesn't work as expected
          zeeman

          You need jboss 7.1.


          Jboss 7.0.2+ might work.

          • 2. Re: Annotation @Asynchronous doesn't work as expected
            lightguard

            You're correct Zee, you should try this on 7.1 Beta, 7.0.2 didn't have any of the async stuff.

            • 3. Re: Annotation @Asynchronous doesn't work as expected
              jboga

              May be you don't need


              the Asynchronous has meant by EJB, but only a simple Asynchronous call to achieve a long work as you may have done with your own thread.


              Try to use the Seam Cron module with its own @Asynchronous annotation.
              It's very simple.

              • 4. Re: Annotation @Asynchronous doesn't work as expected
                zeeman

                Seam Cron is broken, it also needs the app server to support @Async, I already tried it. Not much development activity on Seam Cron. It has been in Alpha stage for many months as far as I know.



                Jeremy Bogatirsky wrote on Dec 06, 2011 06:35:


                May be you don't need

                the Asynchronous has meant by EJB, but only a simple Asynchronous call to achieve a long work as you may have done with your own thread.

                Try to use the Seam Cron module with its own @Asynchronous annotation.
                It's very simple.


                Click HELP for text formatting instructions. Then edit this text and check the preview.

                • 5. Re: Annotation @Asynchronous doesn't work as expected
                  jboga

                  I'm actually using the @Asynchronous annotation provided by Seam Cron, and it works quite well.


                  What do you mean by 'Seam Cron is broken' ?



                  Zee Zain wrote on Dec 06, 2011 22:37:


                  Seam Cron is broken, it also needs the app server to support @Async, I already tried it. Not much development activity on Seam Cron. It has been in Alpha stage for many months as far as I know.


                  Jeremy Bogatirsky wrote on Dec 06, 2011 06:35:


                  May be you don't need

                  the Asynchronous has meant by EJB, but only a simple Asynchronous call to achieve a long work as you may have done with your own thread.

                  Try to use the Seam Cron module with its own @Asynchronous annotation.
                  It's very simple.


                  • 6. Re: Annotation @Asynchronous doesn't work as expected
                    zeeman

                    I used it few months ago, and removed it. I just wanted to run a method in a different thread, simple usecase. Seam Cron did not work. Method ran on the same thread. I asked here and the verdict was to wait till AS 7 supported @Async.


                    Which version of Cron are you using?



                    Jeremy Bogatirsky wrote on Dec 07, 2011 05:33:


                    I'm actually using the @Asynchronous annotation provided by Seam Cron, and it works quite well.

                    What do you mean by 'Seam Cron is broken' ?


                    Zee Zain wrote on Dec 06, 2011 22:37:


                    Seam Cron is broken, it also needs the app server to support @Async, I already tried it. Not much development activity on Seam Cron. It has been in Alpha stage for many months as far as I know.


                    Jeremy Bogatirsky wrote on Dec 06, 2011 06:35:


                    May be you don't need

                    the Asynchronous has meant by EJB, but only a simple Asynchronous call to achieve a long work as you may have done with your own thread.

                    Try to use the Seam Cron module with its own @Asynchronous annotation.
                    It's very simple.





                    Click HELP for text formatting instructions. Then edit this text and check the preview.