Ejb 2.1 定时器 IOException

发布于 2024-10-08 19:11:04 字数 369 浏览 0 评论 0原文

我有一个奇怪的问题,我正在使用 EJB 2.1 计时器对象在一天中的特定时间触发计时器并执行一些内务工作,例如删除文件。计时器按预期触发,但问题是它不会停止。以下是我用来启动计时器的代码:

Timer myTimer = timerService.createTimer(timeOfDay, myInterval, null);

在我的 ejbTimeout 方法中,我有一个删除文件的代码,现在如果我在此方法中收到 IOException,则 EJB 将回滚;并再次调用该方法。计时器会触发 10-15 次然后停止。我正在使用 WAS 6.1,并且之前因 WAS 不遵守 EJB 规范而有过一些不好的经历。还有人有其他解释或理由吗?任何帮助将不胜感激!

I have a weird problem, I am using EJB 2.1 timer object to fire a timer at a specific time in a day and do some housekeeping stuff like deleting files. The timer fires as expected but the problem is that it does not stop. Following is the code I used to initiate the timer:

Timer myTimer = timerService.createTimer(timeOfDay, myInterval, null);

In my ejbTimeout method I have a code which deletes files, now if I get a IOException in this method then the EJB is rolled back; and the method is called again. The timer fires 10-15 times before stopping. I am using WAS 6.1 and I had some bad experiences with WAS not adhering to EJB specks before. Does anybody have any other explanation or justification ? any help would be appreciated !

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

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

发布评论

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

评论(1

七分※倦醒 2024-10-15 19:11:04

不要在 TimeOut 方法中编写逻辑,而是使用线程来删除文件。因此,即使线程中发生异常,您的事务也可能不会回滚。

否则,您可以使用 Bean Managed Transaction 来控制事务,可以相应地回滚 - 提交。

Instead of writing logic inside TimeOut method, use threads to delete the files. So even if exception occurs in thread, your transaction may not get rolled back.

Else you can use Bean Managed Transaction to have control over transactions, can rollback - commit accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文