Tuesday, August 24, 2010

Ambigous documentation and my BMT pain

For the project I'm working on I have an EJB that's operating in a Bean Managed Transaction or BMT. One of the beauties of a BMT is that you can extend your transaction timeout to be longer than the default JTA timeout value for long running DB operations. Sometimes you just have to shift a ton of data around with a minimal amount of domain logic and a BMT suits this nicely.

However I feel there is some ambiguity in the UserTransaction setTransactionTimeout method docs that has caused me a lot of grief.

Modify the timeout value that is associated with transactions started by the current thread with the begin method.

This leaves two possibilities in my mind:

  1. Start a transaction, and set it's timeout.

  2. Set the timeout for all transactions started by the UT, then begin transactions when you want to.

The gotcha is that while both are reasonable interpretations of the API docs, only the second works for me (caveat: I've only tested this on Oracle's OC4J as part of Fusion 10G; other app servers may behave differently).

Needless to say that I took the first option then wondered why I was getting timeouts consistent with the transaction timeout being the value of the server's JTA timeout value, not what I set on the transaction (after starting it). So after a lot of digging, and checking that the container was behaving itself and not starting a transaction when it wasn't, and making sure I was getting access to the correct resources, option two hit me like a brick. Flipping two lines of code, and it all worked perfectly.

When dealing with API doc ambiguities, the thought that "hey I'm reading this wrong" doesn't often enter your head until the very end, when there's blood on the desk from the crack in your skull.

Very annoying!

No comments:

Post a Comment