Management--atomikos of Distributed transaction

Source: Internet
Author: User

In some business scenarios and technical architecture, cross-Library transactions Inevitably, this time how to unify the management of transactions, to ensure that the strong consistency of the transaction is the entire system stable, usable cornerstone. Some middleware such as Tuxedo, CICS is by virtue of this ability to occupy the financial, telecommunications, banking and other large market, and fished out a lot of profits.

In Java, Atomikos as an open source project (with a commercial version), providing the ability to manage distributed transactions. This article mainly validates the simple business scenario to test the distributed transactional consistency under Atomikos management.

Prepare two MySQL instances on a single machine first

1 Download Install the first instance of http://mirrors.sohu.com/mysql/

Mysqld-install net start MySQL mysql-u root-p

2 Installing the second instance copy a MySQL directory modify the port number of the My-default.ini, and so on: Basedir = D:/program files/mysql/mysql Server datadir = D:/program files/my Sql/mysql server/data port = 3307

Run mysqld--install mysql2--defaults-file= "D:\Program files\mysql\mysql server\bin\my-default.ini" net start MYSQL2

Create a table of data in two libraries:

DROP TABLE IF EXISTS account ; CREATE TABLE account ( UserId int (one) not NULL, Money bigint (a) NOT null) Engine=innodb DEFAULT Charset=utf8;

--Records of account

INSERT into account VALUES (' 123 ', ' 0 ');

Then implement the code logic:

The code logic is to implement a random transfer of a certain amount from 1 libraries to 2 libraries, or from 2 to 1 libraries.

During the transfer process, an exception is thrown at a certain probability, and the entire transaction is rolled back. After running for a period of time, see if the amount of two libraries is reconciled correctly.

See GitHub for specific code:

Https://github.com/wfb29/atomikos-test

Management--atomikos of Distributed transaction

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.