What do I need to do to integrate JTA into a Java SE application?

Suppose I want to implement an application container. Not a complete Java EE stack, but I need to provide access to JDBC resources and transactions to third-party code that will be deployed in the application I'm writing.

Suppose I look at JBossTS for transactions. I do not agree with this, but, in my opinion, this is best suited for what I need to do as far as I can judge.

How to integrate support for providing JTA connection and transaction resources in my Java SE application?

+4
source share
7 answers

I decided to use Bitronix Transaction Manager to solve this problem, although there seems to be at least one other option that was not obvious to me at that time (Atomikos).

The solution to this ended up requiring me to also use the JNDI provider included with Tomcat to bind the transaction with the name JNDI. Due to the limitations of this provider, I could not use the default name for the JTA UserTransaction, which is not immediately visible from the documentation.

Thanks everyone for the helpful answers anyway!

+1
source

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.

+7
source

Try Atomicos TransactionsEssentials .

Unlike competing open source JTA / XA implementations, this one was written from the very beginning for JSE. Therefore, it offers premium JDBC and JMS pools, as well as JTA / XA functionality, and it will be very easy for you to integrate into your applications.

Best guy

+3
source

Do not reinvent the wheel. Use the Spring Framework . It already provides this functionality and more.

+2
source

You can use Spring since I'm not so keen.

An example of what you might need is here.

+2
source

JTA supports local transactions and global transactions .

Local transactions can be easily processed using Spring, JPA, or even manually for connections.

Global Transactions REQUIRE Transaction Coordinator. This is a separate product / library that is not available in the public domain (or at least I do not know about it).

So, if I look at the title of your message ("JTA"), the answer will be NO SIMPLE WAY .

If I read your post ("provide access to JDBC resources and transactions"), I would say that Spring, JPA and Hibernate will cover your needs (as I understand them).

PS Correction . JTA does not support local transactions (as people pointed to me), but the case when you only need one connection is, in fact, a local transaction, even if it is controlled by JTA, especially when the Transaction Manager is in the same JVM (as it is often it happens).

+2
source

"JBossTM is terrible. At least if you are hoping for an ACID transaction. The best thing to say about it is that it probably won't ruin it until it has to deal with any failures. And that's not one .. "Most transaction managers (even some commercial ones) really don't work."

You do not know what kind of homework you did to make the above expression, but JBossTS (TM in JBoss since 2006, when it was acquired) does provide full ACID semantics. It was also originally part of the HP NetAction suite, where it was deployed to more important applications than any other open source TM.

+2
source

All Articles