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; @Stateless ...