4 Replies Latest reply on Jul 14, 2010 9:25 PM by Nikolay Elenkov

    Asynchronous methods doesn't run asynchronously :(

    Ilya Dyoshin Novice

      Hello community!


      I'm working on development of several background tasks for my System. Thus I need to create the asynchronous calls:


      here's how I'm doing this using Stateless EJB, the method which triggers this calculation is annotated with @Transactional @TransactionAttribute(REQUIRES_NEW) and @Asynchronous. The method only excepts String parameter of the id (no @Expires, @IntervalCron parameters). When I start using this method in loop - it doesn't makes asynchronous calls :(  the method is invoked one-by-one not as multithreaded asynchronous calls :(   I'm using Quartz with inMemory store (also tried the jdbc store - doesn't helped)


      any idea?


      Ah yeap, the code snippets:


      The main logic


      @Local
      public interface IRezervCalculator {
           
           @Transactional
           public void polici(Polici p, Date calculationDate);
      
           
           @Transactional
           public void cache(Polici p);
           
          
          @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
           @Transactional
           public void cache(String idPolici); 
      }
      



      The scheduler


      @Name("rezervScheduler")
      @Scope(ScopeType.STATELESS)
      public class RezervScheduler {
      
           @Logger
           Log logger;
           
           @In(create=true, value="polici.rezerv.calculator")
           IRezervCalculator calculator;
      
           @Asynchronous
           public void cache(String idPolici) {
                logger.info("scheduling #0 ", idPolici);
                calculator.cache(idPolici);
           }
      } 
      



      And I'm starting this calculations from the REST-service with something like this:


                      Query q = em.createQuery(.........);
                List<Map<String, Object>> obList = q.getResultList() ;
                for (Map<String, Object> m : obList) {
                     String id = m.get("id").toString();
                     rezervScheduler.cache(id);
                }
      



      Any idea how to make things working in parallel?



      Kind regards,
      Ilya Dyoshin