5 Replies Latest reply on Nov 28, 2009 4:40 AM by kapitanpetko

    Asynchronous methods sporadically not invoked?

    jeanluc

      It's happened several times so far, without an obvious pattern: once in a while @Asynchronous methods are not invoked. I have a timer that polls periodically for stuff to process and if anything is found, the task is processed asynchronously. The timer job finds the work to do but then nothing happens... If I restart the server it works.


      I suspect once in a while the timers that are created on the fly for @Asynchronous methods are not created properly, but I don't have proof yet.


      Has anyone else experience it? I'm running Seam 2.1.1 on JBoss 5.1GA


      Thanks.


        • 1. Re: Asynchronous methods sporadically not invoked?
          kapitanpetko

          Which scheduler are you using? Unfortunately, none of them has much logging, so your best bet is to change the scheduler to see if it is a problem with the particular implementation or something else. If you are using Quartz, you can enable its trace/debug log to see if jobs are being scheduled.


          HTH

          • 2. Re: Asynchronous methods sporadically not invoked?
            jeanluc

            I'm using the default dispatcher (the EJB timer - as specified at http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/jms.html and which also matches what I saw in the stack traces)

            • 3. Re: Asynchronous methods sporadically not invoked?
              kapitanpetko

              Jean Luc wrote on Nov 26, 2009 17:36:


              I'm using the default dispatcher (the EJB timer - as specified at http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/jms.html and which also matches what I saw in the stack traces)


              Wel, the default dispatcher is actually the ScheduledThreadPoolExecutor, EJB timers are not used unless you explicitly set <async:timer-service-dispatcher/> in components.xml. How many jobs are you running concurrently? Maybe you are running out of worker threads (10 by default, IIRC)?


              I've found Quartz to be quite reliable, so maybe you want to try that.


              • 4. Re: Asynchronous methods sporadically not invoked?
                jeanluc

                Nikolay Elenkov wrote on Nov 27, 2009 02:14:


                Wel, the default dispatcher is actually the ScheduledThreadPoolExecutor, EJB timers are not used unless you explicitly set <async:timer-service-dispatcher/> in components.xml. How many jobs are you running concurrently? Maybe you are running out of worker threads (10 by default, IIRC)?


                Thanks Nikolay, I had forgotten to add that line. I've just tried and when running the tests (SeamTests) I got an NPE below. Is this known to work with the embedded JBoss as well or is it a limitation?


                
                "Caused by: java.lang.NullPointerException
                     at org.jboss.seam.async.TimerServiceDispatcher.scheduleWithTimerService(TimerServiceDispatcher.java:94)
                     at org.jboss.seam.async.TimerServiceDispatcher.scheduleInvocation(TimerServiceDispatcher.java:65)
                     at org.jboss.seam.async.TimerServiceDispatcher.scheduleInvocation(TimerServiceDispatcher.java:37)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:597)"
                
                



                The missed executions were only with few concurrent tasks, even one  - I observed that while developing. This raises a question, though: are the tasks queued in memory or if there are no threads available, they are simply never executed?



                Thanks.

                • 5. Re: Asynchronous methods sporadically not invoked?
                  kapitanpetko

                  Jean Luc wrote on Nov 27, 2009 19:29:


                  Thanks Nikolay, I had forgotten to add that line. I've just tried and when running the tests (SeamTests) I got an NPE below. Is this known to work with the embedded JBoss as well or is it a limitation?



                  I use Quartz, so no first-hand experience with the Timer service. If it is started in embedded JBoss, it should work. Check the logs for something like 'starting timer service'.




                  The missed executions were only with few concurrent tasks, even one  - I observed that while developing. This raises a question, though: are the tasks queued in memory or if there are no threads available, they are simply never executed?


                  Well, what is does is simply pass your task to Java's ExecutorService. That should throw an exception (RejectedExecutionException), if the task cannot be scheduled, so theoretically either your task gets scheduled or you get an exception. The default pool size is 10, so it's unlikely you exhausted it. You could write a simple program to test it. (unlikely, bu might as well be a bug in Java).


                  I recommend Quartz though, quite reliable and you have the options of persistent jobs and clustering. Use the newest version (1.6.6, IIRC) if you decide to try it.


                  HTH