事务TimeOut EJB影响线程 [英] Transaction TimeOut EJB impact on the thread

查看:194
本文介绍了事务TimeOut EJB影响线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个关于EJB的问题:

A question on EJB:

假设我有一个会话bean,它有一个无限循环。它正在EJB事务下运行。现在当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.

推荐答案


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

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.

这个答案基于我在OC4J 10.3.x(WebSphere 6.x和WebLogic 10.x)上执行了几年的反向工程,可能适用于其他容器以类似的方式。据我所知,交易超时检测在不同的容器中实现不同,但是它们都采用了如下所示的一些常见原则:

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:


  • 事务超时检测通常由容器管理的不同线程执行。相关线程在指定的持续时间内睡眠(通常为1秒),然后唤醒并遍历正在进行的所有交易。如果任何事务超出了指定的超时(通常在各个级别 - JTA容器,EJB等),则线程将标记事务以进行回滚。不要尝试对执行事务的线程进行信号通知事务状态。

  • 当执行事务的线程尝试与JTA协调器或事务资源(一个 XAResource 实例)要做一些工作(例如,发出SQL查询),容器将确定事务已被标记为回滚,并将抛出一个 TransactionRolledBackException

  • 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.

基于上述,可以推断无限循环将除非抛出 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.

请注意,某些容器(如WebLogic)允许检测卡住的线程。这意味着这样的容器能够检测线程是否已经执行超过配置的持续时间的延长的时间段。这并不意味着容器将在检测到该卡被卡住时终止或中断线程。

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.

这篇关于事务TimeOut EJB影响线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆