How to integrate support for providing connection resources and JTA transactions in my J2SE application?
Hi Chris
There are two elements to this problem:
1) Creating a JTA API, mainly UserTransaction, available for application code so that it can start and end transactions. In Java EE, it was published in a famous place in JNDI. If you have a JNDI implementation, this is the way to go (use the JBossTS JNDIManager to help you with the configuration). Otherwise, you need some kind of factory object or injection mechanism. Of course, you can also expose the implementation class right in front of the end user, but this is somewhat unpleasant, as it limits the possibility of replacing the JTA in the future.
public javax.transaction.UserTransaction getUserTransaction() { return new com.arjuna.ats.internal.jta.transaction.UserTransactionImple(); }
Here it is - now you can start, complete and roll back transactions. Some containers also publish the TransactionManager class for applications in a similar way, but it is really intended to be used by the container itself and is rarely required by application code.
2) Automatic commissioning of XAResources automatically. Resource managers i.e. Databases and message queues have drivers that implement XAResource. Each time the application receives a connection with the resource manager, the corresponding XAR source must be passed to the JTA implementation so that it can manage the resource manager as part of 2PC. Most application servers have a JCA that handles this automatically. In environments without one, you need an alternative to keep the application code from having to perform this tedious task manually. TransactionalDriver bundled with JBossTS handles this for JDBC connections. XAPool is also worth considering.
JBossTS has been deployed in many environments over the years. Some of the lessons learned are described in the Integration Guide http://anonsvn.jboss.org/repos/labs/labs/jbosstm/trunk/atsintegration/docs/ ], and if you want to work, you can look at the tomcat http integration work : //anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/tomcat-integration/ ]
JBossTM is terrible. At least if you are hoping for an ACID transaction.
Hello erickson
I donβt think Id comes to "terrible." Its incredibly powerful and customizable, which can make out of the box a little harder for beginners. The correct recovery configuration is especially difficult, so I fully approve of your comment on thorough testing. In addition, I do not know of any documented test cases in which it currently cannot provide ACID results when used with resource managers that are compliant with specifications. If you have such a case, or simply more constructive suggestions for improvement, tell JBoss to fix the problem.
Do not reinvent the wheel. Use Spring Frames. It already provides this functionality and more.
-1 Spring does not provide a JTA implementation, just a shell for various third-party ones. This is a common misunderstanding.
JTA supports local transactions and global transactions.
Another misconception. I'm afraid. The JTA specification deals only with XA, that is, with global transactions. There are various well-known methods for creating a JTA transaction manager for local transactions. This is usually due to terminating the connection in XAResource. While most implementations support this, it is actually beyond the scope of the specification, and so you should check with the provider before choosing a JTA implementation if you need this behavior.