2 Replies Latest reply on Apr 5, 2012 5:19 AM by Stephen Coy

    Using @Asynchronous in JBoss 7

    bryan.solan Newbie

      I created a simple JSF/EJB project to try out @Asynchronous in JBoss 7, but the results were not what I expected. getMyResult() gets called from the JSF layer which calls the async method getMyResultSubroutine().


      Here's what my bean looks like:


      public class TestAsyncBean extends implements Test {
          private Logger log;
          public void getMyResultSubroutine() {
              log.info("Starting method getMyResultSubroutine()");
              try {
              } catch (InterruptedException e) {
              log.info("Ending method getMyResultSubroutine()");
          public String getMyResult() {
              log.info("getMyResult() : BEFORE @Async call");
              log.info("getMyResult() : AFTER @Async call");
              return "Some result"; 


      Any my output:


      08:58:07,152 INFO  [com.test.TesAsynctBean] (http-- getMyResult() : BEFORE @Async call

      08:58:07,152 INFO  [com.test.TesAsync} (http-- Starting method getMyResultSubroutine()

      08:58:10,153 INFO  [com.test.TesAsync] (http-- Ending method getMyResultSubroutine()

      08:58:10,153 INFO  [com.test.TesAsync] (http-- getMyResult() : AFTER @Async call


      I was expecting at least the message "Ending method getMyResultSubroutine()" to come after the message "getMyResult() : AFTER @Async call"


      What am I missing here?

        • 1. Re: Using @Asynchronous in JBoss 7
          jaikiran pai Master

          Bryan Solan wrote:


              public String getMyResult() {


          You are doing a plain Java call from getMyResult to getMyResultSubroutine() method. That won' introduce any EJB semantics to the call. See this on how to get it working https://community.jboss.org/message/525521#525521

          • 2. Re: Using @Asynchronous in JBoss 7
            Stephen Coy Master

            From the EJB 3.1 Spec §4.5.1

            Asynchronous method invocation semantics only apply to the no-interface, Local business, and Remote business client views. 


            In other words, you have to invoke the @Asynchronous method from an external bean reference:



            class MyClient {



                 private TestAsyncBean testBean;



                 ... someMethod(...) {








            This is because the EJB machinery needs the opportunity to invoke the method through a proxy. I've used the no-interface view above, but you could also use your interface if the method was declared on it.

            1 of 1 people found this helpful