是否可以创建一个专门用于管理 EJB 3.1 计时器的 EJB?

发布于 2024-12-25 04:18:31 字数 460 浏览 2 评论 0原文

这可能是一个愚蠢的问题,但是是否可以专用一个 EJB 来管理整个容器的所有计时器?我不知道如何实现这一点,因为我对 Java EE 的经验并不丰富,但我正在考虑一些类似于可以访问此计时器 bean 的单个会话 bean 的方法,并且会话 bean 传递一个函数指针以及作业本身的元数据?在计时器 bean 之上,可以构建一个 GUI 或管理框架,至少可以查看哪些作业正在运行及其当前状态?

基本上我需要/想要拥有 Quartz 的一些功能(能够停止、启动、修改作业),同时使用 EJB 3.1 计时器。试图弄清楚这是否是一种遥远的可能性。

编辑:正如一些人所指出的,问题的症结在于计时器服务无法获取整个容器的所有计时器。我的想法是在一个特殊的计时器 bean 中创建所有计时器,在其中可以管理所有计时器。问题是我不知道如何做到这一点,或者这是否可能。我曾经尝试过将函数指针(无论如何都可以在java中尽可能接近它们)与计时参数一起传递给计时器bean,但这看起来真的很恶心。

This might be a stupid question, but would it be possible to dedicate an EJB to managing all the timers for the entire container? I don't know how this would be accomplished as I'm not all that experienced with Java EE, but I'm thinking something along the lines of individual session beans having access to this timer bean, and the session beans pass in a function pointer along with the meta data for the job itself? On top of the timer bean, it would then be possible to build a GUI or management framework to, at the very least, see what jobs are running and their current status?

Basically I need/want to have some of the functionality of Quartz (being able to stop, start, modify jobs) while using EJB 3.1 timers instead. Trying to figure out if this is even a remote possibility or not.

Edit: As some have noted, the crux of the problem is that the timer service cannot obtain all timers for the entire container. My idea is to create all timers within a special timer bean where all the timers can be managed. The problem is I have no idea how to do this, or whether this is possible. I've played with passing function pointers (as close as you can get to them in java anyway) to the timer bean along with timing parameters, but this seems really gross.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轻拂→两袖风尘 2025-01-01 04:18:31

您可能正在寻找 javax.ejb.TimerService 。将其注入到您的 bean 中:

@Resource
private SessionContext sessionContext;

然后,作为示例,您可以迭代所有计时器:

TimerService timerService = sessionContext.getTimerService();
for (Timer timer : timerService.getTimers()) {
    timer.cancel(); //etc.
}

You are probably looking for the javax.ejb.TimerService. Inject it into your bean:

@Resource
private SessionContext sessionContext;

Then, as an example, you can get iterate over all timers:

TimerService timerService = sessionContext.getTimerService();
for (Timer timer : timerService.getTimers()) {
    timer.cancel(); //etc.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文