如何停止无尽的 EJB 3 计时器?

编程入门 行业动态 更新时间:2024-10-27 18:18:15
本文介绍了如何停止无尽的 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 计时器?

本文发布于:2023-11-06 17:11:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   EJB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!