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

Get Java EE 8 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.