Java Reference
In-Depth Information
public void createTimer(){
timerService.createSingleActionTimer(duration,
new TimerConfig());
}
Next, we will create a callback method named timeout and use the @Timeout
annotation on top of the method. In the timeout method, we could, for example,
reinitialize our singleton by invoking the setupTheatre method. Nothing fancy;
however, this should give you an idea of how to get working with a single action timer.
@Timeout
public void timeout(Timer timer){
logger.info("Re-building Theatre Map.");
setupTheatre();
}
Scheduling timer events
If you want to schedule timed notifications at fixed intervals, the simplest way is
to use the @Schedule annotation. The @Schedule annotation takes a series of
comma-delimited settings to express a time or set of times, much as the Unix cron
utility does. Each setting corresponds to a unit of time such as an hour or minute. A
simple repeating event occurring every minute can be expressed using the @Sched-
ule annotation as follows:
@Schedule(second="0", minute= "*", hour= "*")
You can find some more details about building the time string at ht-
tp://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html .
For the purpose of our example, we will create a stateless session bean that will act
as an automatic buying system and therefore buy tickets at our ticketing store. So
we will add one competitor in our quest for the best seat at the theatre!
Search WWH ::




Custom Search