Java – impact of transaction timeout EJB on threads

Questions about EJB:

Suppose I have a session bean with infinite loops It runs under EJB transactions Now when the EJB transaction times out, the infinite loop thread will be interrupted or the container will stop running the infinite loop thread

Solution

This answer is based on my OC4J 10.3 x,WebSphere 6. X and Weblogic 10 X has been reverse engineered for several years and may be applied to other containers in a similar way As far as I know, transaction timeout detection is implemented differently in different containers, but they all adopt some common principles as follows:

>Transaction timeout detection is usually performed in different threads managed by the container The related thread sleeps for a specified duration (usually 1 second), then wakes up and iterates over all ongoing transactions If any transaction exceeds the specified timeout (usually at various levels - JTA container, EJB, etc.), the thread marks the transaction for rollback Does not attempt to signal the transaction status to the thread executing the transaction. > When the thread executing the transaction attempts to interact with JTA coordinator or transaction resource (xaresource instance) to perform some work (for example, issuing SQL query), the container will determine that the transaction has been marked for rollback and will throw transactionrolledbackexception

Based on the above, it can be inferred that an infinite loop will never be broken unless a transactionrolledbackexception is thrown In other words, the loop is interrupted only when a transaction activity is attempted within the loop; If such an activity is not executed, the loop will retain its properties for execution indefinitely

Note that some containers, such as Weblogic, allow detection of "stuck" threads This means that such a container can detect whether a thread has executed for an extended period of time beyond the configured duration This does not mean that the container will terminate or interrupt the thread when it detects a jam

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>