我想每两秒唤醒一次 ejb 计时器。为此,我创建 ScheulerExpression 作为下面的代码......
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 容器不会每两秒唤醒一次调度程序。
对此有什么建议吗? 我怎样才能让表情每两秒醒来一次。
谢谢, 冈詹。
最佳答案
有两件事可能导致问题:
导入语句似乎不正确,它是
com.sun.jersey.spi.resource.Singleton
,但应该是javax.ejb.Singleton
。尝试删除
@LocalBean
注释。
关于timer - EJB @Timeout 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10860230/