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网站入侵第二波(LeaRun.信息化快速开发框架 已被笔者拿下)

    笔者小学文化,语言组织能力差,写的不通的地方请大家将就着看,不喜勿喷. 上篇我讲了如何在上传文件中入侵服务器,這次我们稍微多讲一点. 还是先讲下流程: 1.上传代码页面  我上传的是ashx页面. 2 ...

  2. 清空KindEditor富文本编辑器里面的内容方法

    //清空KindEditorKindEditor.instances[0].html(""); 0表示第一个KindEditor编辑器对象 详情见链接:http://www.new ...

  3. javascript位置相关知识点整理

    1.css指定元素的位置采用的是文档坐标: 2.js查询元素位置的方法返回的是元素在视口中的位置,即视口坐标: 如何获得元素的位置和尺寸 获得元素的位置和尺寸可以通过getBoundingClient ...

  4. [转]mysql免安装版配置

    现在mysql有一个installer,相当于安装包管理器.包含mysql的各个组件,比如workbench,各个语言的connector.十分方便,不用就可惜了.实在没有必要下载zip版,自己配置. ...

  5. java中的URLConnection

    *URLConnection是个抽象类,它有两个直接子类分别是HttpURLConnection和JarURLConnection.另外一个重要的类是URL,通常URL可以通过传给构造器一个Strin ...

  6. 【python】实践中的总结——列表『持续更新中』

    2016-04-03 21:02:50 python list的遍历 list[a::b]   #从list[a] 开始,每b个得到一个元组,返回新的list 举个例子: >>> l ...

  7. 基于tiny4412原生uboot修改制作SD启动并烧写到emmc

    最近入手tiny4412的标准板,底板SDK型号为1506.但是因为友善之臂提供的superboot不能进入boot菜单,此时我就不能通过tftp下载内核和通过nfs挂载根文件系统,于是想自己做个ub ...

  8. Fragment 与Activity之间的通信

    1.Fragment-->Activity 在fragment中的onAttach()中引用Activity实现的接口实例. 2Activity-->Fragment 直接调用 3多个Fr ...

  9. C#反射设置属性值和获取属性值

    /// /// 获取类中的属性值 /// /// /// /// public string GetModelValue(string FieldName, object obj) { try { T ...

  10. [转]CSS Display(显示) 与 Visibility(可见性)

    CSS Display(显示) 与 Visibility(可见性) display属性设置一个元素应如何显示,visibility属性指定一个元素应可见还是隐藏. 隐藏元素 - display:non ...