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

查看:32
本文介绍了如何停止无尽的 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.

我忘记打电话取消然后它不会停止 .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天全站免登陆