如何阻止无休止的EJB 3计时器? [英] How to stop endless EJB 3 timer?

查看:113
本文介绍了如何阻止无休止的EJB 3计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是EJB 3的新手。我使用以下代码启动无限的EJB 3计时器
然后在JBOSS 4.2.3上部署它

I am new to EJB 3 . I use the following code to start endless EJB 3 timer then deploying it on JBOSS 4.2.3

@Stateless
public class SimpleBean  implements SimpleBeanRemote,TimerService  {

@Resource
TimerService timerService;
private Timer timer ;
@Timeout
public void timeout(Timer timer) {
    System.out.println("Hello EJB");

 }
}

然后调用它

  timer = timerService.createTimer(10,  5000, null);

效果很好。我创建了一个客户端类,它调用一个创建计时器的方法和一个在计时器超时时调用的方法。

It works well. I created a client class that calls a method that creates the timer and a method that is called when the timer times out.

我忘记调用cancel
然后它不会停止.redeploy与取消呼叫​​永远不会停止它。重启Jboss 4.2.3从不停止它。我怎么能停止EJB计时器?
感谢您的帮助。

I forget to call cancel then it does not stop .redeploy with cancel call never stop it. restart Jboss 4.2.3 never stop it. How I can stop EJB timer ? Thanks for helping.

推荐答案

    public void stop(String timerName) {
    for(Object obj : timerService.getTimers()) {
        Timer t = (Timer)obj;
        if (t.getInfo().equals(timerName)) {
        t.cancel();
        }
    }
}

这篇关于如何阻止无休止的EJB 3计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆