开发者

Are EJB3 Timers inherit to the beans they are created by?

Timers are created in EJB3 using the TimerService.createTimer(), and are then run via whatever callback method that's annotated by the @Timeout annotation, i.e:

@Resource
private TimerService timerService;

public void createHampster() {
    Hampster hamps开发者_如何学JAVAter = new Hampster("Fluffy III");
    timerService.createTimer(3000, 3000, hampster);
}

(...)

@Timeout
public void feedHampster(Timer timer) {
    Hampster hampster = (Hampster) timer.getInfo()
    //(...)
}

So, my question is, do these two blocks of code need to be within the same bean? Are timers inherit to the bean in which they were created, or are they global? My own testing suggests but former, and I haven't found anything definite in the documentation.


They are tied to the bean that creates them. EJB 3 specification sections 18.2 says:

The bean class of an enterprise bean that uses the timer service must provide a timeout callback method.

and

When the time specified at timer creation elapses, the container invokes the timeout callback method of the bean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜