4 Replies Latest reply on Oct 24, 2011 6:04 AM by baku1

    Asynch calls in a cluster

    mgvarley

      Hi all - I am in the process of moving my seam app from single server to cluster, so far this is going pretty well but I'm running into a problem with my asynchronous calls.  I have a daily job which downloads the latest exchange rates from Yahoo.  As the jobs are firing up at exactly the same time (in parallel on the two server nodes) they are causing a deadlock on the database, the error message is as follows:


      [JDBCExceptionReporter] Deadlock found when trying to get lock; try restarting transaction



      My web.xml looks like this:


      <async:timer-service-dispatcher />
      <component class="org.jboss.seam.async.ThreadPoolDispatcher" precedence="40" />



      The class looks like this:


      @Asynchronous
      @Transactional
      public Timer schedule(@Expiration Date expiration,
                      @IntervalDuration Long interval) {
              log.info("Downloading today's rates: " + System.currentTimeMillis());
              if (isAlreadyRunToday())
                      return null;
              if (process())
                      log.info("Rates downloaded: " + System.currentTimeMillis());
              else
                      log.error("Rate download failed: " + System.currentTimeMillis());
              return null;
      }
      



      What do I need to do to stop these two jobs blocking each other?


      Thanks,


      mark




        • 1. Re: Asynch calls in a cluster
          kapitanpetko

          You should use the quartz dispatcher. It has built-in cluster support (using the database) and load-balancing
          (jobs are run on the less loaded node). Most importantly, it guarantees that only a single instance of a job
          is running at a time. Just make sure that your nodes' clocks are synchronized (NTP).

          • 2. Re: Asynch calls in a cluster
            mgvarley

            Quartz took a while to setup but is now working perfectly - thanks for the tip Nikolay.  For anyone else using quartz I managed to get this working with a combination of the seam docs (which I must say are a little light on the config required), Devon Hillard's (as-always) excellent blog www.digitalsanctuary.com/tech-blog/java/jboss/seam/quartz-scheduling-and-seam-part-1.html and the Quartz docs from their website.  I recommend using the latest quartz.jar library class from the Quartz website as opposed to the one bundled with Seam, the reason being is that you will need to use the quartz db scripts to build the db tables and I had numerous problems trying to synch these with the Seam bundled quartz.jar before I reverted to using the latest jar (1.6.4) from the quartz website.

            • 3. Re: Asynch calls in a cluster
              richardq

              i agree with the above comment, the internet is with a doubt growing into the most important medium of communication across the globe and its due to sites like this that ideas are spreading so quickly.


              Confidential Conversions

              • 4. Re: Asynch calls in a cluster
                baku1

                Hello!


                Suppose, I would like to send async event to ALL cluster members AND i would like to call async method ONLY ONE cluster member. (Workload balancing by responsibilty of cluster WLM...)


                In this case, Quartz help me, if I can use two Quartz instances on all cluster members. (One for async events and one for async methods.) I have to use nontypical behaviour of Quartz, that schedulers of Quartz instances with identical instanceId on cluster fires on all cluster members. Perhaps, this is not pretty solution, but works with present versions of Quartz.


                Question: Is possible to use more than one Quartz instance for underlying async support in Seam? Or is there any idea about workaround solution for problem in my first sentence?