You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Steve K <sh...@myrealbox.com> on 2003/08/31 20:30:28 UTC

User managed distributed transactions, thread pooling, and flow

Hey all --

I am working on using user managed distrubuted transactions from flow.  I have 
Cocoon 2.1, Tomcat 4.1.27, JOTM 1.4.3, and the JSQLConnect JDBC driver.  I 
believe I have it working and would like to share some things and ask a 
question.

The biggest problem I had was the scenario when I started a transaction from 
flow and there was an unhandled exception, and the transaction was not 
cleaned up.   When this happened, the next request would return a "Nested 
transactions not supported" exception.  I suspect that this is because Tomcat 
(or Cocoon) has a thread pool servicing the requests, and since I did not 
clean up the transaction when the exception was thrown, the transaction 
remained active and bound to one of the threads in the pool.  Therefore, the 
next request that reuses this thread and tries to start its own transaction 
will get the "Nested transactions not supported" exception.

To help solve this problem, I created a small TransactionHelper JavaScript 
class that keeps track of the current connection(s) and transacion and has a 
cleanup() method that I call from a finally block.  This method will attempt 
to rollback the active transaction and close any open connections.

This seems to work, however, I wonder if there is a better place for this 
code?  Who should be responsible for making sure there are no active 
transactions on threads in the thread pool?  When I start a transaction, I 
could store a reference to the transaction using ThreadLocal, and somewhere 
right before the thread is returned to the pool, this could be checked and 
cleaned up (and an exception thrown) before the thread is returnd to the 
pool.

Where would be an appropriate place in Cocoon to add this code?

cheers,
-steve