Suppose developer wants to create an EJB component that performs data validation every hour.
Given the following Stateless session bean:
What is the minimum modification you would need to make to the bean to support notification from
the TimerService once the timer expires?
A.
Modify the verify external orders method to look like this:
@TimedOut
private void verifyExternalOrders () {
/ / do something
}
B.
Modify the verify external orders method to look like this:
@EjbTimeOut
private void verifyExternalOrders () {
/ / do something
}
C.
Modify the verify external orders method to look like this:
@ejbTimeOut
private void verifyExternalOrders () {
/ / do something
}
D.
Modify the verify external orders method to look like this:
@TimeOut
private void verifyExternalOrders () {
/ / do something
}
Explanation:
Programmatic Timers
When a programmatic timer expires (goes off), the container calls the method annotated
@Timeout in the beans implementation class. The @Timeout method contains the business logic
that handles the timed event.
The @Timeout Method
Methods annotated @Timeout in the enterprise bean class must return void and optionally take a
javax.ejb.Timer object as the only parameter. They may not throw application exceptions.
@Timeout
public void timeout(Timer timer) {
System.out.println(“TimerBean: timeout occurred”);
}
Reference: The Java EE 6 Tutorial, Using the Timer Service