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:
- Start a transaction, and set it's timeout.
- 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.