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

    Seam 3 Cron module @Asynchronous

    Benniu Ji Newbie

      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?