/[projects]/miscJava/Test3/src/dk/thoerup/schedulesamples/TimedEjb.java
ViewVC logotype

Diff of /miscJava/Test3/src/dk/thoerup/schedulesamples/TimedEjb.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1280 by torben, Thu Apr 7 21:17:29 2011 UTC revision 1281 by torben, Thu Apr 7 21:26:36 2011 UTC
# Line 24  public class TimedEjb implements TimedOb Line 24  public class TimedEjb implements TimedOb
24    
25          @Resource          @Resource
26          private SessionContext sessionCtx;          private SessionContext sessionCtx;
27            int count;
28                    
29          public void startTimer() {          public void startTimer() {
30                    
31                  TimerService timerService = sessionCtx.getTimerService();                  TimerService timerService = sessionCtx.getTimerService();
32                                    
33                  Calendar now = Calendar.getInstance();  
34                  //Timer timer = timerService.createTimer( (5 * 1000), null); //singleshot timer                  //Timer timer = timerService.createTimer( (5 * 1000), null); //singleshot timer
35                  //timerService.createTimer(10*1000, 5000, null); //repeating timer                  timerService.createTimer(10*1000, 5000, null); //repeating timer
36                                    
37                  // otherwise use schedule expression to create more complex schedules                  // otherwise use schedule expression to create more complex schedules
38                  // in this case fire once every minute when the seconds is == 10                  // in this case fire once every minute when the seconds is == 10
39                  ScheduleExpression se = new ScheduleExpression().second(10).minute("*").hour("*");                  //ScheduleExpression se = new ScheduleExpression().second(10).minute("*").hour("*");            
40                    //System.out.println(se.toString());
41                    //timerService.createCalendarTimer( se );
42                                    
43                  System.out.println(se.toString());                  count = 0;
                 timerService.createCalendarTimer( se );    
44          }          }
45                    
46          @Override          @Override
47          public void ejbTimeout(Timer timer) {          public void ejbTimeout(Timer timer) {
48                  System.out.print("timeout ....");                  
49                    count++;
50                    
51                    System.out.print("timeout .... " + count);
52                    
53                    
54                    if (count >= 10) {
55                            timer.cancel();
56                    }
57          }          }
58    
59  }  }

Legend:
Removed from v.1280  
changed lines
  Added in v.1281

  ViewVC Help
Powered by ViewVC 1.1.20