Transaction TimeOut EJB impact on the thread

巧了我就是萌 提交于 2019-12-07 13:42:08

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6623278/transaction-timeout-ejb-impact-on-the-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!