You can use the Create EJB Timer wizard to create Enterprise JavaBeans (EJB) Timers and add them to your project.
Before you begin
You must have a Java™ project, an EJB 3.1 project, an
EJB 3.2 project, or a web project that is created in your workspace.
Procedure
- In the Java EE perspective, right-click your project, and
select . The Create EJB Timer wizard opens.
- In the Source folder field, select the source folder for the new
bean.
- In the Java package field, type the package name for the new bean.
- In the Class name field, type the name that you want to assign to the
enterprise bean. By convention, bean names begin with an uppercase letter.
Note: You can use Unicode characters for the bean name, but Unicode characters are not supported for
enterprise bean packages and classes that are associated with enterprise beans.
- In the Schedule field, modify the preinstalled calendar-based timer
expressions for this timer.
- Optional: Select Non-persistent.
When you make the selection, the persistent element of the Schedule annotation is set to
false.
- Click Finish.
Results
In the Java class editor, in the scheduleTimeout
method, you can see the @Schedule annotation with the calendar-based timer expressions typed in the
wizard. If the Non-persistent option was checked, the persistent element is set to
false.
package com.ibm.test;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;
@Stateless
public class MyTimer {
/**
* Default constructor.
*/
public MyTimer() {
// TODO Auto-generated constructor stub
}
@SuppressWarnings("unused")
@Schedule(second="*/10", minute="*", hour="8-23", dayOfWeek="Mon-Fri",
dayOfMonth="*", month="*", year="*", info="MyTimer", persistent=false)
private void scheduledTimeout(final Timer t) {
System.out.println("@Schedule called at: " + new java.util.Date());
}
}