1 Reply Latest reply on Aug 8, 2012 6:35 PM by kwatsen

    EJB asynchronous method

    maverik87

      I'm using JBoss 7.1.1 final. I have a stateful EJB with an asynchronous method. From a jsp I call a synchronous method of the previous EJB and this method call the asynchronous one of the same EJB via proxy.

       

      @Stateful
      @Remote(IExcursionDAOWithPrefetch.class)
      public class ExcursionDAOWithPrefetch implements IExcursionDAOWithPrefetch {
       
      @Resource SessionContext ctx;
       
      @EJB(lookup=...) IExcursionDAO excursionDAO;

       
      ...

       
      public Excursion findExcursionById(int id, boolean loadCoordinates) {
         
      // Retrieve from cache
         
      Excursion excursion = cache.getExcursionById(id);
         
      if(excursion == null) {
             
      // Retrieve from database
              excursion
      = excursionDAO.findExcursionById(id, loadCoordinates);
              logger
      .info("excursion not in cache");
         
      }
         
      else {
              logger
      .info("excursion in cache");
         
      }
          ctx
      .getBusinessObject(IExcursionDAOWithPrefetch.class).loadCache(excursion);

         
      return excursion;
       
      }

       
      @Asynchronous
       
      public void loadCache(Excursion excursion) {     
         
      if(excursion != null) {
              cache
      .invalidateCache();
              cache
      .addExcursion(excursion);
             
      List<Excursion> closeExcursions = excursionDAO.findCloseExcursions(excursion, 10);
             
      if(closeExcursions != null) {
                 
      for(Excursion exc : closeExcursions) {
                      cache
      .addExcursion(exc);
                 
      }
             
      }
         
      }
       
      }
      }

       

      EDIT: if I make ExcursionWithDAOPrefetch stateless, the asynchronous method loadCache() works asynchronously; when ExcursionWithDAOPrefetch is stateful, the loadCache() method works synchronously.

       

      loadCache() method is executed asynchronously but the jsp awaits its end even though it calls findExcursionById() method (and not loadCache()).

      Can someone help me?

       

      Message was edited by: maverik87