Java Reference
In-Depth Information
EJB timer service
Stateless session beans and Message-Driven Beans (another type of EJB discussed
in the next chapter) can have a method that is executed automatically at regular
intervals. This functionality is useful in case we want to execute some logic
periodically (once a week, every day, every hour, and so on) without having to
explicitly call any methods. This functionality is achieved by the EJB Timer Service .
In order to use the EJB timer service, we need to use the @Schedule annotation to
specify when our method will be called. The following example illustrates how to
use the EJB timer service:
package com.ensode.ejbtimer.ejb;
import java.util.Date;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.ejb.Schedule;
public class EJBTimerDemo {
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
@Schedule(hour = "*", minute = "*", second = "*/30")
public void logMessage() {
System.out.println("logMessage() method invoked at: "
+ new Date(System.currentTimeMillis()));
Search WWH ::

Custom Search