日期:2014-05-16 浏览次数:20531 次
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).