In some cases it may be necessary to enlist participants that aren't two-phase commit aware into a two-phase commit transaction. If there is only a single resource then there is no need for two-phase commit. However, what if there are multiple resources in the transaction? In this case, the Last Resource Commit optimization (LRCO) comes into play. It is possible for a single resource that is one-phase aware (i.e., can only commit or roll back, with no prepare), to be enlisted in a transaction with two-phase commit aware resources. The coordinator treats the one-phase aware resource slightly differently, in that it executes the prepare phase on all other resource first, and if it then intends to commit the transaction it passes control to the one-phase aware resource. If it commits, then the coordinator logs the decision to commit and attempts to commit the other resources as well.

In order to use the LRCO, your XAResource implementation must extend the com.arjuna.ats.jta.resources.LastResourceCommitOptimisation marker interface (it provides no methods). When enlisting the resource via Transaction.enlistResource, JBossTS will ensure that only a single instance of this type of participant is used within each transaction. Your resource will be driven last in the commit protocol: no invocation of prepare will occur.

Note: By default an attempt to enlist more than one instance of a LastResourceCommitOptimisation class will fail and false will be returned from Transaction.enlistResource. This behaviour can be overridden by setting the propertycom.arjuna.ats.jta.allowMultipleLastResources in conf/jbossjta-properties.xml (JBoss-4.x) or conf/jbossts-properies.xml (JBoss 5) to "true" (not "YES"). This property goes in the JTA properties section (name="arjuna"). However, before doing so you should read the Section on enlisting multiple one-phase aware resources.

WARNING: setting com.arjuna.ats.jta.allowMultipleLastResources to true when using 1pc resources will increase your chances of getting a heuristic outcome.(outcome in which some resources are committed and others aren't).

In order to utilize the LRCO in a distributed environment, it is necessary to disable interposition support. It is still possible to use implicit context propagation.

Enlisting multiple one-phase aware resources

As discussed in the Transaction Core documentation, in order to guarantee consistency (atomicity) of outcome between multiple participants (resources) within the same transaction, the two-phase commit protocol is used with a durable transaction log. In the case of possessing a single one-phase aware resource, it is still possible to achieve an atomic (all or nothing) outcome across resources by utilizing the Last Resource Commit Optimization, as explained earlier.

However, there may be situations where multiple one-phase aware resources are enlisted within the same transaction. For example, a legacy database running within the same transaction as a legacy JMS implementation. In these situations it is not possible to achieve atomicity of transaction outcome across multiple resources because none of them enter the prepare (waiting for final outcome) state: they commit or rollback immediately when instructed by the transaction coordinator, without knowledge of other resource states and without any way of undoing should subsequent resources make a different choice. This can result in data corruption or heuristic outcomes.

If you see this warning, then you have run into this problem:

WARN Adding multiple last resources is disallowed. Current resource is <resource>

In these situations we recommend one of the following approaches:

  • Wrap the resources in compensating transactions. See the Web Services transactions guides for further details.

  • Migrate the legacy implementations to two-phase aware equivalents.  For DataSources deployed on JBoss Application Server, this is as simple as changing from <local-tx-datasource> to <xa-datasource>.  See ConfigDataSources for more information.

  • Refactor the code to use separate transactions.  If you simply need to read from one DataSource and insert processed results into another, you may not want or need 2-phase commit (and thus the above optimization).  In an EJB3 session bean, this can be accomplished by simply delegating the read to a separate method and annotating it with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW).  This causes the calling method's Transaction to suspend, wait for the read to complete, and resume.

In the cases where neither of these options are viable, JBossTS does support the enlistment of multiple one-phase aware resources within the same transaction. In order to do this, see the section on the Last Resource Commit Optimization (JBossTS Programmers Guide 4.2.3, Chapter 3, Extended XAResource control).

Caution:    Even when this support is enabled, JBossTS will issue warnings when it detects that the option has been enabled (You have chosen to enable multiple last resources in the transaction manager. This is transactionally unsafe and should not be relied upon.) and when multiple one-phase resources are enlisted within the transaction (This is transactionally unsafe and should not be relied on.).

Enlisting multiple 1-phase aware participants in the same transaction的更多相关文章

  1. [转]Entity Framework Sprocs with Multiple Result Sets

    本文转自:https://msdn.microsoft.com/en-us/data/jj691402.aspx Entity Framework Sprocs with Multiple Resul ...

  2. Understanding JTS--reference

    Part I-An introduction to transactions If you look at any introductory article or book on J2EE, you' ...

  3. 了解和解决SQL SERVER阻塞问题(copy)

    http://support.microsoft.com/kb/224453 Summary In this article, the term "connection" refe ...

  4. 十几个remote control software

    5 alternatives to LogMeIn Free for remote PC access VNC VNC, or Virtual Network Computing, isn’t its ...

  5. A multiprocessing system including an apparatus for optimizing spin-lock operations

    A multiprocessing system having a plurality of processing nodes interconnected by an interconnect ne ...

  6. Methods and Systems for Enhancing Hardware Transactions Using Hardware Transactions in Software Slow-Path

    Hybrid transaction memory systems and accompanying methods. A transaction to be executed is received ...

  7. WCF学习系列四--【WCF Interview Questions – Part 4 翻译系列】

    WCF Interview Questions – Part 4   This WCF service tutorial is part-4 in series of WCF Interview Qu ...

  8. 转:45 个 LoadRunner 面试问题(附答案)_纯英文,太有逼格了

    What is load testing? - Load testing is to test that if the application works fine with the loads th ...

  9. How do you build a database?

    在reddit上看到的一篇讲解数据库实现的文章,非常有意思,在这里记录一下. 回答者technical_guy: Its a great question, and deserves a long a ...

随机推荐

  1. 快速开发之代码生成器(asp.net mvc4 + easyui + knockoutjs)

    一.前言 作为一个码农这么多年,一直在想怎么提高我们的编码效率,关于如何提高编码效率,我自己的几点体会 1.清晰的项目结构,要编写代码的地方集中 2.实现相同功能的代码量少并且清晰易懂 3.重复或有规 ...

  2. WPF 3D模型 3D场景

    1.首先得说明的是这并不是真正的3D,模型被导出为一系列的单个图片,例如一个3D户型图,以某个视角旋转360°,渲染出一系列连续的单个图片文件. 2.在Image.MouseMove事件中添加相应代码 ...

  3. 学习SQLite之路(二)

    下面就是真正关于数据库的一些知识了: 20160614更新 参考: http://www.runoob.com/sqlite/sqlite-tutorial.html 1. SQLite创建表: 基本 ...

  4. operating expense & captial expenditure

    营运成本(营业成本, operating expense, OPEX) 指的是运行企业的持续性.消耗性的支出,与之对照的是资本支出(captial expenditure, CAPEX).例如:购买影 ...

  5. android之fragment的使用

    android中的fragment与html中的div很类似,下图中通过左边的按键可以控制右边的显示内容.右边的内容就是一个fragment,通过点击按键来控制fragment的实现. 工程目录 需要 ...

  6. Android开发之AutoCompleteTextView的简单使用

    这里只谈简单的使用: 代码xml: <AutoCompleteTextView android:id="@+id/actv" android:layout_width=&qu ...

  7. 关于图像文章垂直无缝连接滚动——JS实现

    <!-- 作者:chenyehuacecil@163.com 时间:2015-02-04 描述:实现整篇文章从下到上的无缝连接滚动--><html xmlns="http: ...

  8. 【JavaEE企业应用实战学习记录】getConnListener

    Listener:当Web应用在Web容器中运行时,Web应用内部会不断地发生各种事件,如Web应用被启动.Web应用被停止,用户Session开始,用户session结束.用户请求到达等,这些对We ...

  9. jqMobile中的dialog和popup的区别

    主要区别是:dialog默认含回退按钮.并且dialog在1.4版中已经过时,1.5中将会移除. 下面是 原文1: Using a Dialog Window as a Popup A jQuery ...

  10. jquery里的on方法使用

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <script src ...