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 |
} |
} |