Stateless session beans and message-driven beans can have a method that is executed periodically at regular intervals of time. This can be accomplished by using the EJB timer service. The following example illustrates how to take advantage of this feature:
package net.ensode.javaeebook; //imports omitted @Stateless public class EjbTimerExampleBean implements EjbTimerExample { private static Logger logger = Logger.getLogger(EjbTimerExampleBean.class .getName()); @Resource TimerService timerService; public void startTimer(Serializable info) { Timer timer = timerService.createTimer (new Date(), 5000, info); } public void stopTimer(Serializable info) { Timer timer; Collection timers = timerService.getTimers(); for (Object object : timers) { timer = ((Timer) object)...