Transaction TimeOut EJB 对线程的影响
关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个答案基于我几年前在 OC4J 10.3.x、WebSphere 6.x 和 WebLogic 10.x 上执行的逆向工程,并且可能以类似的方式应用于其他容器。据我所知,事务超时检测在不同容器中的实现方式有所不同,但它们都采用了一些共同的原则,如下所示:
TransactionRolledBackException
。根据以上内容,可以推断,除非抛出
TransactionRolledBackException
,否则无限循环永远不会被打破。换句话说,只有当在循环内尝试事务活动时,循环才会被打破;如果没有执行此类活动,则循环将保留其无限期执行的属性。请注意,某些容器(例如 WebLogic)允许检测“卡住”线程。这意味着此类容器能够检测线程的执行时间是否超出了配置的持续时间。这并不意味着容器在检测到线程被卡住时将终止或中断线程。
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:
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 aTransactionRolledBackException
.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.
不,容器通常不可能自动检测无限循环。某些应用程序服务器可能会检测到事务已超时或 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.