我想每兩秒喚醒一次ejb計時器。對於我創造ScheulerExpression如下面的代碼...EJB @Timeout不能正常工作
package com.fks.nclp.ejb.timer.service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.ScheduleExpression;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import com.sun.jersey.spi.resource.Singleton;
@LocalBean
@Singleton
@Startup
public class HelloWorldService {
@Resource
TimerService timerService;
@PostConstruct
public void initialize(){
System.out.println("EJB PRE CONSTRUCT");
ScheduleExpression expression = new ScheduleExpression();
//SET TIMER TO 2 SEC
expression.hour("*");
expression.minute("*");
expression.second("*/2");
timerService.createCalendarTimer(expression,new TimerConfig("TimerScheduler",false));
}
@Timeout
public void startTimer(){
System.out.println("THIS IS EJB TIMER PROGRAM");
}
}
但是...... EJB容器不是每兩秒鐘後醒來的調度。
對此有何建議? 我怎樣才能讓表達每兩秒醒來。
謝謝, Gunjan。
您是否獲取了正在調用的方法的任何日誌/異常,或者根本沒有被創建。 –
ScheduleExpression看起來很合適。 Timer.getNextTimeout()返回什麼(通過createCalendarTimer的返回值)?你在使用什麼應用程序服務器?你的標籤說ejb-3.0,但ScheduleExpression是EJB 3.1;你的應用服務器版本是否支持EJB 3.1? –
我已經使用GlassFish 3.1並且很抱歉...我已經添加了GlassFish服務器庫,它默認提供了EJB3.1 –