JBoss Community

EJB asynchronous method

created by maverik87 in EJB3 Development - View the full discussion

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);
           
}
       
}
   
}
 
}
}

 

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

Can someone help me?

Reply to this message by going to Community

Start a new discussion in EJB3 Development at Community