Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | 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:

- annotating an existing method (see "Using Annotations")

- by implementing the `javax.ejb.TimedObjectinterface`.

## 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");