5 Replies Latest reply on Sep 23, 2011 1:32 AM by lsqfjbn

    Seam 3 Cron module @Asynchronous

    lsqfjbn

      Hi, all


      I wrote the following cron job for test. But it is not work as I expcted


            

      @Asynchronous
           public void printTime(){
                
                try {
                     Thread.sleep(10000);
                } catch (InterruptedException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
                
                SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
               String datetime = tempDate.format(new java.util.Date());
               System.out.println(datetime);
               
           }
           
           public void schedule(@Observes @Every(value=Interval.SECOND) Trigger t){
                this.printTime();
           }




      The actual output is like:



      16:09:07,929 INFO  [STDOUT] 2011-06-10 16:09:07
      
      16:09:08,879 INFO  [STDOUT] 2011-06-10 16:09:08
      
      16:09:09,880 INFO  [STDOUT] 2011-06-10 16:09:09
      
      16:09:10,880 INFO  [STDOUT] 2011-06-10 16:09:10
      
      16:09:18,880 INFO  [STDOUT] 2011-06-10 16:09:18
      
      16:09:19,879 INFO  [STDOUT] 2011-06-10 16:09:19
      
      16:09:20,879 INFO  [STDOUT] 2011-06-10 16:09:20
      
      16:09:21,879 INFO  [STDOUT] 2011-06-10 16:09:21
      
      16:09:29,880 INFO  [STDOUT] 2011-06-10 16:09:29
      
      16:09:30,880 INFO  [STDOUT] 2011-06-10 16:09:30
      
      16:09:31,880 INFO  [STDOUT] 2011-06-10 16:09:31
      
      16:09:32,880 INFO  [STDOUT] 2011-06-10 16:09:32





      The interval is 1 second, and in the method it will sleep 10 seconds.
      What I can see in the output is that at the first 4 records the interval is 1 second, but the interval between 4th and 5th record is 8 second.
      It's strange. Can anyone tell me why this happened?

        • 1. Re: Seam 3 Cron module @Asynchronous
          peteroyle.howardmoon.hitcity.com.au

          Hi Benniu,


          Thanks for checking out Seam Cron, and for this interesting test case. What has happened is you have run into the maximum thread-pool size limit of 4 which is currently hard-coded into the Quartz scheduling Seam Cron implementation. Once the first four jobs are submitted no more can proceed until the first one finishes. Note that the next four jobs also fill up the thread pool in a similar fashion (as evidenced by the 8-second gap at :21 to :29). I have verified this theory locally using your test code.


          I have created this jira to make things like thread-pool size configurable by the end developer.


          Cheers,


          Pete.

          • 2. Re: Seam 3 Cron module @Asynchronous
            lsqfjbn

            Thank you, Pete. It'll be very nice if the pool size is configurable.


            Before the ticket in jira is fixed, is there any walk around?

            • 3. Re: Seam 3 Cron module @Asynchronous
              peteroyle.howardmoon.hitcity.com.au

              I have just increased the hard-coded number from 4 to 100, so you could build from source to replace the version in your machine's local repository:




              git clone git://github.com/seam/cron.git
              cd cron
              mvn clean install






              That's about the best thing I can think of to tide you over until the problem is fixed and Alpha2 is released.

              • 4. Re: Seam 3 Cron module @Asynchronous
                lsqfjbn

                Thanks Pete!
                That really helps.

                • 5. Re: Seam 3 Cron module @Asynchronous
                  lsqfjbn

                  Hi, Peter


                  Thanks for setting the hard-coded number from 4 to 10.


                  But I found that one more place may need to be udpated.
                  It's QuartzAsynchronousProvider.class. In this class, the thread pool size is also hard coded to 4.


                  Thanks,
                  Benniu