O'Reilly logo

Java EE 7 with GlassFish 4 Application Server by David R. Heffelfinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introduction to the EJB Timer Service

Stateless session beans and message-driven beans can have a method that is executed periodically at regular intervals of time. This can be accomplished using the EJB Timer Service. The following example illustrates how to take advantage of this feature:

package net.ensode.glassfishbook; //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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required