Creating an EJB timer by using wizards

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

  1. In the Java EE perspective, right-click your project, and select New > Other > EJB > EJB Timer. The Create EJB Timer wizard opens.
  2. In the Source folder field, select the source folder for the new bean.
  3. In the Java package field, type the package name for the new bean.
  4. 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.
  5. In the Schedule field, modify the preinstalled calendar-based timer expressions for this timer.
  6. Optional: Select Non-persistent.

    When you make the selection, the persistent element of the Schedule annotation is set to false.

  7. 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());
    }
}
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: tcreatejbtimerwiz.html