2009-07-08 67 views
1

與TimerService相關,我可以定義兩個Timer實例,並將每個計時器綁定到同一個EJB中特定的(不同的)註解@Timeout的方法嗎?TimerService EJB 3

感謝, 杆

+0

爲什麼要這麼做?一個計時器可以爲許多EJB服務,不是嗎? – skaffman 2009-07-08 09:37:31

回答

2

不是真的。

但是,您可以定義 2個定時器

ctx.getTimerService().createTimer(1000, 1000, "timerA"); 
ctx.getTimerService().createTimer(1000, 1000, "timerB"); 

,並有一個超時的方法來處理兩個定時器超時。

@Timeout 
    public void handleTimeout(Timer timer) { 
    String info = (String)timer.getInfo(); 
    if ("timerA".equals(info) { handleTimerEventA(); } 
    else if ("timerB".equals(info) { handleTimerEventB(); } 
}