Java Reference
In-Depth Information
We can implement our bean either as a stateless or as a singleton session bean. We
can also choose to create either a local or a remote interface. Local interfaces are
optional, and remote interfaces are required only if we need to access our session
bean from a different JVM. So, in our example, we choose not to create either one.
In the Method schedule text area, we need to enter the attributes and values of the
@Schedule annotation that will be added to the generated session bean.
The @Schedule annotation uses a syntax similar to the cron utility
commonly found in Unix and Unix-like operating systems such
as Linux. Refer to
newbie/unix/cron-1.html for a good introduction to cron .
After clicking on Finish , our new session bean is generated, as shown in the
following code:
package com.ensode.ejbtimer.ejb;
import java.util.Date;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
public class EjbTimerDemo {
@Schedule(hour = "*", minute = "*", second = "*/30")
public void myTimer() {
System.out.println("Timer event: " + new Date());
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
Notice how the values and attributes of the @Schedule annotation match the values
we entered in the wizard. We used the value "*" for its hour attribute to specify that
the method should be invoked every hour. We used the value of "*" for the minute
attribute as well to specify that the method should be invoked every minute. Finally,
we used the value of "*/30" for its second attribute to specify that the method
should be invoked every 30 seconds.
Search WWH ::

Custom Search