Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring an EJB 3.0 EJB with a J2EE Timer

You can configure a J2EE timer on an EJB 3.0 stateless session bean or message-driven bean.

You can access the timer service using annotations and dependency injection (see "Using Annotations"), using the initial context API (see "Using Initial Context").

You can implement the timeout call back by:

Using Annotations

Example 25-1 shows how to use resource injection to acquire a J2EE timer in an EJB 3.0 EJB.

Example 25-1 Using @Resource to Acqurie a J2EE Timer in an EJB 3.0 EJB

@Stateless public class EmployeeServiceBean implements EmployeeService
{
    ...
    @Resource Timer EmpDurationTimer;
    ...
    }
}

Using Initial Context

Example 25-2 shows how to use the initial context to look up a J2EE timer in an EJB 3.0 EJB.

Example 25-2 Using Initial Context to Look Up an EJB 3.0 J2EE Timer

InitialContext ctx = new InitialContext();
TimerService ts = ctx.getTimerService();
Timer myTimer = ts.createTimer(timeout, "EmpDurationTimer");