我怎么能够创造出一份每秒6秒的工作,而这项工作在提出申请时就自动开始?
目前,我有这一类人使用时间,但这一进程在开始部署时不会自动启动。
所有这一切,只有EJBs, 在JBos4.3和没有WAR的欧洲复兴开发银行,只有EJBs
@Stateless
public class MyJobBean implements MyJob {
private static final long EJECUTION_INTERVAL=6000;
@Resource
private TimerService ts;
@PostConstruct // This not work in deploy, only when somebody calls the EJB
public void init() {
System.out.println("Post Constructor Method init() Invoked");
ts.createTimer(EJECUTION_INTERVAL, null);
}
@Timeout // Fired by the timer
public void myJOBProcess(Timer timer) {
System.out.println("the job was invoked");
ts.createTimer(EJECUTION_INTERVAL, null); //create another future ejecution
}
@PreDestroy
public void tidyUp() {
System.out.println("Canceling scheduled Timers");
for (Object obj : ts.getTimers()) {
Timer timer = (Timer)obj;
timer.cancel();
System.out.println("Timer Canceled");
}
}
}
预支