`

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics