Enlisting multiple 1-phase aware participants in the same transaction

 

 

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.).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
常用PIC系列8位单片机芯片引脚符号的功能 doc 同时1分提供其他PIC相关资源 包括: 《PIC单片机入门与实战》 pdf 张明峰 北京航空航天大学出版社 本书从PIC中档系列单片机的结构介绍入手,系统阐述PIC单片机开发过程的最基本步骤;通过引入设计实例,深入浅出地介绍PIC单片机的各主要功能模块。书中介绍的代码实例将以汇编指令为主,最后专门介绍PIC单片机的C语言编程。读者对象主要是对PIC单片机感兴趣的初学者或准备用PIC单片机进行产品开发的工程师,对已经熟悉PIC单片机开发的工程师也可以作为设计时的参考。 《PIC单片机C语言编程指南》 pdf 包括详细的PICC函数库 《PIC单片机图解入门教程》 pdf 王伟民 清晰彩图 《PIC单片机实用教程-基础篇》 pdf 李学海 北京航天航空大学出版社 本书兼顾PIC全系列,共分9章,内容包括:基本概念、PIC16F877硬件概况、指令系统、汇编程序设计、集成开发环境、在线调试工具、定时器、中断逻辑以及应用系统性能优化。突出特点:通俗易懂、可读性强、系统全面、学练结合、学用并重、实例丰富、习题齐全、教者轻松、学者有趣。本教程全书共分2篇,即基础篇和提高篇,分2册出版,以适应不同课时和不同专业的需要,也为教师和读者增加了一种可选方案。 《PIC单片机实用教程——提高篇》 pdg 李学海 北京航天航空大学出版社 本书兼顾PIC全系列,共分9章,内容包括:基本概念、PIC16F877硬件概况、指令系统、汇编程序设计、集成开发环境、在线调试工具、定时器、中断逻辑以及应用系统性能优化。突出特点:通俗易懂、可读性强、系统全面、学练结合、学用并重、实例丰富、习题齐全、教者轻松、学者有趣。本教程全书共分2篇,即基础篇和提高篇,分2册出版,以适应不同课时和不同专业的需要,也为教师和读者增加了一种可选方案。 《PIC单片机轻松入门》 pdf 朱英彪 清华大学出版社 本书着重介绍了PIC单片机的基本原理,从硬件结构和软件指令入手,结合一系列基本的操作实验,提供给读者详细的实验内容、系统设计、程序编写以及程序说明。在另外一方面,本书采用经济的配备为背景来加以说明,使得读者仅需准备一些在电子市场就可买到的常用工具,就可全身心地投入到PIC单片机的学习过程中。 《PIC系列单片机原理和程序设计》 pdf 窦振中 北京航空航天大学出版社 本书介绍当前在十分繁荣的单片机世界中异军突起的一种单片机——Microchip公司的PIC系列单片机。这个系列单片机具有以下体现微控制器工业发展新趋势的特点:高速度、低工作电压、低功耗、I/O口直接驱动LED能力、低价位、小体积、指令简单易学易用等。内容包括:该系列主要芯片的系统结构和工作原理;片内各种丰富的部件和资源的使用方法;全系列芯片的指令系统和汇编语言程序设计技术及实例;提供了常用的运算子程序。本书内容全面而实用,语言逻辑性强,通俗流畅,易学易懂,适于作广大从事单片机开发与应用的工程技术人员的自学用书和大学相关专业研究生、本科、专科、中专各种单片机应用毕业设计的参考用书以及培训班的教材。 《PIC系列单片机应用设计与实例》 pdf 窦振中 北京航空航天大学出版社 本书作为《PIC系列单片机原理和程序设计》的姊妹篇,介绍当前单片机世界中异军突起的美国Microchip公司的PIC系列单片机的应用设计技术和应用实例。内容相当丰富,包括并行的各种串行存储器、接口电路、人机对话通道、中断系统、IC总线串行通信等系统扩展技术,应用系统开发及其常用工具、集成开发环境MPLAB软件包和十分有实用价值的典型应用实例。应用实例有交流数字电压表、电力周波表、闪光报警器、移动式客房控制器、不间断电源UPS控制器、均匀分布随机数程序、4阶IIR数字滤波器程序、快速傅里叶变换程序、即热式电热水器模糊逻辑温控器、汉字热敏微型打印机等。书中给出了大部分应用实例的硬件电路、程序流程图以及汇编语言源程序。这些内容是作者近几年业部分开发工作的实践总结,有一些就是实际批量生产产品的提练和推广。 本书内容丰富而实用,语言逻辑性强,通俗流畅,易学易懂;适于广大从事单片机开发和应用的工程技术人员自学,也可作大学相关专业研究生、本科、专科、中专各种单片机应用、毕业设计的参考用书,以及培训班的教材。 《PIC系列单片机的开发应用技术》 pdf 武锋 北京航空航天大学出版社 本书结合作者的开发应用试验,介绍了美国Microchip公司的PIC系列单片机的开发应用概况及其源程序的建立和汇编过程,并以PIC16系列产品为例介绍了目标程序的软件模拟仿真调试技术及其一些开发应用的演示试验和开发应用设计范例等内容。本书在开发应用演示试验和开发应用设计范例的介绍中均给出了硬件电路的设计及其相应的源程序,并在附录中收录了一些PIC系列单片机开发应用的实用资料,具有实用价值。本书可提供配套磁盘,内有相关的汇编与模拟调试等工具软件及主要源程序清单(磁盘的文件目录参见附录J),以供读者选购。本书通俗易懂、实用性强,可供从事单片机开发与应用的有关工程技术人员和单片机爱好者以及高等院校相关专业的师生阅读参考。 工具——PIC单片机编程助手Net 绿色小工具 用于PIC单片机开发 包括代码生成等实用功能 PIC单片机选型表 xls 常用PIC系列8位单片机芯片引脚符号的功能 doc

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值