我正在尝试在带有 Java Sun 1.6 的 RedHat Linux 上使用带有 JBOSS 4.3 的计时器,计时器已创建但从未触发
米课是
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyTimerBean implements MyTimer,TimedObject {
private static final Logger logger = Logger.getLogger(MyTimer.class);
@Resource
private TimerService ts;
@Resource
private SessionContext ctx;
private TimerService ts2;
Timer y;
private String miString=null;
public void startTimer() throws NamingException {
logger.debug("DRFXML starting..");
miString="Timers exists";
Timer x = ts.createTimer( 6000L, null);
logger.debug("DRFXML 1.Next Timeout "+x.getNextTimeout());
x = ts.createTimer( 36000L, null);
logger.debug("DRFXML 2.Next Timeout "+x.getNextTimeout());
x = ts.createTimer( 1036000L, null);
logger.debug("DRFXML 3.Next Timeout "+x.getNextTimeout());
x= ts.createTimer(15000, null);
logger.debug("DRFXML 4.Next Timeout "+x.getNextTimeout());
ts2 = ctx.getTimerService();
y = ts2.createTimer(30000, "Another");
logger.debug("DRFXML 5.Next Timeout "+y.getNextTimeout());
this.showTimers();
}
public void showTimers(){
if (ts.getTimers()==null){
logger.error("DRFXML Error Timer is null");
}
else if (ts.getTimers().size()==0){
logger.error("DRFXML Error 0 Timers ");
}else
{
logger.debug("DRFXML Timers = "+ts.getTimers().size());
}
if (ts2.getTimers()==null){
logger.error("DRFXML Error Timer2 is null");
}
else if (ts2.getTimers().size()==0){
logger.error("DRFXML Error 0 Timers in TS2 ");
}else
{
logger.debug("DRFXML Timers2 = "+ts2.getTimers().size());
}
logger.debug("DRFXML My String="+miString);
if(y==null){
logger.debug("DRFXML Error timer is null");
}
else{
//This line raise the exception
logger.debug("DRFXML timer y NextTimeout"+y.getNextTimeout());
}
}
@PreDestroy
public void tidyUp() {
logger.debug("DRFXML Killing Timers....");
for (Object obj : ts.getTimers()) {
Timer timer = (Timer)obj;
timer.cancel();
logger.debug("DRFXML Timer Canceled");
}
}
@Timeout
public void ejbTimeout(Timer arg0) {
logger.debug("DRFXML TimeOut!!");
System.out.println("DRFXML EJBTimeOut!!");
}
}
界面是
@Local
public interface MyTimer {
void startTimer() throws NamingException;
@PreDestroy
void tidyUp();
public void showTimers();
}
这是日志
2012-02-18 21:17:44 CLST DEBUG DRFXML starting..
2012-02-18 21:17:44 CLST DEBUG DRFXML 1.Next Timeout Sat Feb 18 21:17:50 CLST 2012
2012-02-18 21:17:44 CLST DEBUG DRFXML 2.Next Timeout Sat Feb 18 21:18:20 CLST 2012
2012-02-18 21:17:44 CLST DEBUG DRFXML 3.Next Timeout Sat Feb 18 21:35:00 CLST 2012
2012-02-18 21:17:44 CLST DEBUG DRFXML 4.Next Timeout Sat Feb 18 21:17:59 CLST 2012
2012-02-18 21:17:44 CLST DEBUG DRFXML 5.Next Timeout Sat Feb 18 21:18:14 CLST 2012
2012-02-18 21:17:44 CLST DEBUG DRFXML Timers = 5
2012-02-18 21:17:44 CLST DEBUG DRFXML Timers2 = 5
2012-02-18 21:17:44 CLST DEBUG DRFXML My String=Timers exists
2012-02-18 21:17:44 CLST DEBUG DRFXML timer y NextTimeoutSat Feb 18 21:18:14 CLST 2012
当再次调用 showTimers 方法时,在同一个 EJB 中,计时器不存在!!!:,(
2012-02-18 21:17:46 CLST DEBUG DRFXML Error 0 Timers
2012-02-18 21:17:46 CLST ERROR DRFXML Error 0 Timers in TS2
2012-02-18 21:17:46 CLST DEBUG DRFXML My String=Timers exists
Caused by: javax.ejb.NoSuchObjectLocalException: Timer was canceled
at org.jboss.ejb.txtimer.TimerImpl.assertTimedOut(TimerImpl.java:402)
at org.jboss.ejb.txtimer.TimerImpl.getNextTimeout(TimerImpl.java:257)
at cl.walmart.presto.ti.servicios.solicitud.beans.RescataXmlFirmadoBean.showTimers(RescataXmlFirmadoBean.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
可以看到“My String”存在,是同一个EJB!!
为什么我的“定时器被取消”?
注意:在我的 PC 的 Jboss Local 中,代码可以工作,但在带有 redhat 的 linux 中不能工作!!>:oC
提前致谢