XA Datasource 与 Non-XA Datasource 区别

An XA transaction, in the most general terms, is a "global transaction"that may span multiple resources. A non-XA transaction always involvesjust one resource.

An XA transaction involves a coordinating transaction manager, withone or more databases (or other resources, like JMS) all involved in asingle global transaction. Non-XA transactions have no transactioncoordinator, and a single resource is doing all its transaction workitself (this is sometimes called local transactions).

XA transactions come from the X/Open group specification ondistributed, global transactions. JTA includes the X/Open XA spec, inmodified form.

Most stuff in the world is non-XA - a Servlet or EJB or plain oldJDBC in a Java application talking to a single database. XA getsinvolved when you want to work with multiple resources - 2 or moredatabases, a database and a JMS connection, all of those plus maybe aJCA resource - all in a single transaction. In this scenario, you'llhave an app server like Websphere or Weblogic or JBoss acting as theTransaction Manager, and your various resources (Oracle, Sybase, IBM MQJMS, SAP, whatever) acting as transaction resources. Your code can thenupdate/delete/publish/whatever across the many resources. When you say"commit", the results are commited across all of the resources. Whenyou say "rollback", _everything_ is rolled back across all resources.

The Transaction Manager coordinates all of this through a protocolcalled Two Phase Commit (2PC). This protocol also has to be supportedby the individual resources.

In terms of datasources, an XA datasource is a data source that canparticipate in an XA global transaction. A non-XA datasource generallycan't participate in a global transaction (sort of - some peopleimplement what's called a "last participant" optimization that can letyou do this for exactly one non-XA item).

For more details - see the JTA pages on java.sun.com. Look at theXAResource and Xid interfaces in JTA. See the X/Open XA DistributedTransaction specification. Do a google source on "Java JTA XAtransaction".


XA 连接与非 XA 连接不同。一定要记住 XA 连接参与了 JTA 事务。这意味着 XA 连接不支持 JDBC 的自动提交功能。同时,应用程序一定不要对 XA 连接调用 java.sql.Connection.commit() 或者 java.sql.Connection.rollback() .相反,应用程序应该使用 UserTransaction.begin()、 UserTransaction.commit() 和 serTransaction.rollback() .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值