Sunday, June 11, 2006

halting problem (a.k.a) infinite block problem

There is a huge caveat with using container-managed transactions with JMS message-driven beans in a certain scenario. Let's say you have an EJB component (any type of component) that sends and then receives a message all within one big container-managed transaction. In this case, the send operation will never get its message on the queue, because the transaction doesn't commit until after the receive operation ends. Thus, you'll be waiting for the receive operation to complete forever. This is called the infinite block problem, also known as the halting problem in computer science.

An easy solution to this problem is after sending the request message, you can call commit() on the JMS Session, which is your JMS transaction helper object. This causes the outgoing message buffer to be flushed. Hence, the receive operation does not have to wait forever for the transaction to commit to get a message.

[ref: Mastering EJB, Third Edition, Ed Roman et al.]

No comments: