简体   繁体   English

EJB 2.1计时器IOException

[英]Ejb 2.1 Timer IOException

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. 我有一个奇怪的问题,我正在使用EJB 2.1计时器对象在一天中的特定时间触发计时器,并做一些客房整理工作,例如删除文件。 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; 在我的ejbTimeout方法中,我有一个删除文件的代码,现在,如果在此方法中得到IOException,则EJB回滚; and the method is called again. 并再次调用该方法。 The timer fires 10-15 times before stopping. 计时器在停止前会触发10-15次。 I am using WAS 6.1 and I had some bad experiences with WAS not adhering to EJB specks before. 我正在使用WAS 6.1,以前在WAS上有一些不好的经验,他们以前没有遵守EJB规范。 Does anybody have any other explanation or justification ? 有人还有其他解释或理由吗? any help would be appreciated ! 任何帮助,将不胜感激 !

Instead of writing logic inside TimeOut method, use threads to delete the files. 使用线程删除文件,而不是在TimeOut方法内部编写逻辑。 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. 另外,您可以使用Bean托管事务来控制事务,可以回滚-相应地提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM