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