Transaction TimeOut EJB 对线程的影响

发布于 2024-11-19 05:23:03 字数 106 浏览 1 评论 0原文

关于 EJB 的问题:

假设我有一个具有无限循环的会话 bean。它在 EJB 事务下运行。现在,当EJB的事务超时时,是否会导致无限循环线程中断,或者容器将停止运行无限循环的线程。

A question on EJB:

Let's say I have a session bean which has an infinite loop. It is running under a EJB transaction. Now when the transaction of the EJB times out, will that cause the infinite loop thread to break or container will stop the thread running the infinite loop.

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

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

发布评论

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

评论(2

天生の放荡 2024-11-26 05:23:03

现在,当EJB的事务超时时,是否会导致无限循环线程中断,或者容器将停止运行无限循环的线程。

这个答案基于我几年前在 OC4J 10.3.x、WebSphere 6.x 和 WebLogic 10.x 上执行的逆向工程,并且可能以类似的方式应用于其他容器。据我所知,事务超时检测在不同容器中的实现方式有所不同,但它们都采用了一些共同的原则,如下所示:

  • 事务超时检测通常在容器管理的不同线程中执行。相关线程休眠指定的持续时间(通常为 1 秒),然后唤醒并迭代所有正在进行的事务。如果任何事务超过了指定的超时(通常在各个级别 - JTA 容器、EJB 等),则线程将标记该事务以进行回滚。不会尝试向执行事务的线程发出有关事务状态的信号。
  • 当执行事务的线程尝试与 JTA 协调器或事务资源(XAResource 实例)交互以执行某些工作(例如,发出 SQL 查询)时,容器将确定该事务已被标记为回滚,并且会抛出 TransactionRolledBackException

根据以上内容,可以推断,除非抛出 TransactionRolledBackException,否则无限循环永远不会被打破。换句话说,只有当在循环内尝试事务活动时,循环才会被打破;如果没有执行此类活动,则循环将保留其无限期执行的属性。

请注意,某些容器(例如 WebLogic)允许检测“卡住”线程。这意味着此类容器能够检测线程的执行时间是否超出了配置的持续时间。这并不意味着容器在检测到线程被卡住时将终止或中断线程。

Now when the transaction of the EJB timesout, will that cause the infinite loop thread to break or container will stop the thread running the infinte loop.

This answer is based on reverse-engineering that I performed a couple of years back on OC4J 10.3.x, WebSphere 6.x and WebLogic 10.x, and might apply to other containers in a similar manner. As far as I remember, the transaction timeout detection is implemented differently in different containers, but they all employ certain common principles stated as follows:

  • The transaction timeout detection is usually performed in a different thread managed by the container. The pertinent thread sleeps for a specified duration (usually 1 second), then wakes up and iterates through all the transactions in progress. If any transaction has exceeded the timeout specified (usually at various levels - the JTA container, the EJB etc.), then the thread will mark the transaction for rollback. No attempt will be made to signal the thread executing the transaction about the transaction state.
  • When the thread performing the transaction attempts to interact with the JTA co-ordinator or with a transactional resource (an XAResource instance) to do some work (for instance, issue a SQL query), the container would determine that the transaction has been marked for a rollback, and would throw a TransactionRolledBackException.

Based on the above, it can be inferred that the infinite loop will never be broken unless a TransactionRolledBackException is thrown. In other words, the loop will be broken only when a transactional activity is attempted within the loop; if no such activity is performed, then the loop will retain it's property to execute indefinitely.

Note that certain containers like WebLogic allow for detection of "stuck" threads. This means that such containers have the ability to detect if a thread has been executing for an extended period of time beyond a configured duration. This done not mean that the container will terminate or interrupt the thread when it detects that one is stuck.

非要怀念 2024-11-26 05:23:03

不,容器通常不可能自动检测无限循环。某些应用程序服务器可能会检测到事务已超时或 EJB 已处于活动状态很长时间。

No, it is not possible in general for a container to automatically detect an infinite loop. Some application servers might detect that the transaction has timed out or that the EJB has been active for a long time.

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