官术网_书友最值得收藏!

The Java Transaction API

The Java Transaction API (JTA) is the element responsible for providing the API responsible for ensuring the consistency of your data in the widest sense. In our quote manager, it is only applied to the database data but it can be applied to JMS messages, potentially files if you use connectors, and so on.

Without going through the details and protocol, the idea is to ensure, across multiple systems, that either all commits or all rollbacks but not something in between are done ensuring the consistency of the system (which is one common issue mixing NoSQL systems).

To do that, JTA uses what we call a two phases commit protocol:

  • Ask all systems to prepare the commit which means the system must verify and ensure it will be able to commit in next phase
  • Ask all systems to actually do the commit

A lot of transaction manager or servers are optimized for the case of a single resource to limit all the associated overhead.

In our quote manager application we only have a database, so we should benefit from these optimizations in most servers. Nonetheless, we still use JTA backbone and don't fallback on JPA transaction management (RESOURCE_LOCAL) which is faster.

What is important to know with JTA is that a transaction is bound to a thread. Each resource has its representation and identifier, a complete lifecycle (see XAResource). There is a transaction bound registry to store the data (a bit like a @TransactionScoped bean) and the listeners to integrate with the transaction lifecycle.

All of that is not true in terms of memory and CPU cycles but can be justified if you need it, either because you have multiple systems or because you use your server JTA monitoring (you rarely have monitoring with RESOURCE_LOCAL in administration UI).

主站蜘蛛池模板: 田阳县| 安顺市| 报价| 彰武县| 扎囊县| 浦县| 克东县| 金阳县| 福建省| 塘沽区| 阳西县| 广河县| 建瓯市| 屏东县| 万安县| 台北县| 舒兰市| 临沭县| 西昌市| 礼泉县| 清徐县| 淮南市| 磐石市| 贵溪市| 西峡县| 亚东县| 泾源县| 临朐县| 威远县| 蒙阴县| 民丰县| 会东县| 泽普县| 荃湾区| 广汉市| 汕头市| 兴隆县| 沅江市| 林芝县| 金山区| 尚志市|