Spring Distributed Transaction Learning notes

Source: Internet
Author: User

Recent projects have used distributed transactions, this article and the next two articles summarize the knowledge learned in the project.

Distributed transactions have a certain impact on performance, so it is not the best solution to avoid the best possible design by avoiding it.

distributed transactions (distributed transactions), also known as XA transactions (XA is the name of a protocol), called Global transaction in spring, refers to a transaction that involves different transactional resources . For example, different databases, Message Queuing. Transactional Resources support transaction control commands such as commit and rollback.

There are two ways to implement XA transactions by using an application server that implements full Java EE functionality:

1. In general, XA transactions are implemented through the Java EE Application Server, the CMT (Container Managed Transaction). Application Server implements JTA (Java Transaction API), The app uses Jndi to get the application server's JTA usertransaction. jta API is more complex, developers need to study more JTA details, using spring transaction management can simplify JTA programming model. However, it is still necessary to rely on an application server that implements the Java EE function.

2. No application server (standalone) is required, or only a lightweight application server is required, such as TOMCAT,TOMCAT does not implement all Java EE functions. Add a third-party package that supports JTA, such as Atomikos,jtom, in your app.

Structure of a distributed transaction:

In the figure, 1 represents the interface between the app and the resource Manager rm, which is either the local interface of the resource manager or the XA interface. If you use Transaction Manager TM to manage distributed transactions,
You do not need the app to call RM directly, that is, the 1 interface will not be used.
2 represents the interface between the app and the TM, the UserTransaction, which is similar to ordinary transaction management excuses, and is an interface with operations such as commit and rollback. Use this interface just as a transaction processes only one data source. The app controls the commit or rollback of a transaction through this interface.
3 is the interface between the TM and RM, is a two-phase commit (2 phase commit) process, two-phase commit is simply a data source transaction to be submitted two times before the actual commit. The operation is controlled by the TM, and the app does not call interface 3 directly.

The next two articles will cover implementing distributed transactions using Spring+hibernate+atomikos+tomcat and implementing distributed transactions using Spring+mybatis+atomikos+tomcat.

Reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#transaction

Http://www.javaworld.com/article/2077963/open-source-tools/distributed-transactions-in-spring--with-and-without-xa.html

Http://www.javaworld.com/article/2076126/java-se/transaction-management-under-j2ee-1-2.html

Http://www.javaworld.com/article/2077714/java-web-development/xa-transactions-using-spring.html

Spring Distributed Transaction Learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.