- coordinator。而且总是第一个参与全局事务的 XAResource的实例充当 coordinator,因为coordinator的委任决定于TX开始后,第一次RMI request发 送给哪个server。Connection conn = getConnection ("t3://localhost:8001", "TestXADS") 用于指定这个global transaction的 coordinator为8011这个server。如果没有这个语句,thread1,thread2启动后, 它们开始XA操作时,每个XAResouce都会把自己当作这个TX的coordinator (Thread1委任8011,Thread2委任8021),这样就会出现如下的异常,
javax.transaction.TransactionRolledbackException: Current server is the coordinator and transaction is not found.It was probably rolled back and forgotten already.
at weblogic.rjvm.BasicOutboundRequest.sendReceive (BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke (ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke (ReplicaAwareRemoteRef.java:247)
at weblogic.jdbc.common.internal.RmiDataSource_814_WLStub.getConnection (Unknown Source)
at weblogic.transaction.internal.DriverTest1.getConnection (DriverTest1.java:39)
at weblogic.transaction.internal.DriverTest1.access$0 (DriverTest1.java:34)
at weblogic.transaction.internal.DriverTest1$SQLThread.run (DriverTest1.java:135)
2:某个全局事务中启动的线程,不能同时操作同一个XAResource,比如 Thread1操作datasource1和 datasource2,thread2操作datasource2和 datasource3。Weblogic中,我们做XA操作的时候,需要同后端的 XA Resource Manager交互,交互中我们会多次调用xaStart(xid, flag),xaEnd(xid, flag) 这里的flag可以使NOFLAGS、TMSUCESS、TMRESUME、TMSUSPEND等。如果我们在同 一个全局事务的多个线程中同时操作某个RESOURCE,那么就可能我们不同线程先 后给这个RESOUCE的RM发送相同的FLAG,比如xaStart(xid, TMSUSPEND),即两个 线程同时发送TMSUSPEND,这样会引发XA_ERR,如下:
java.sql.SQLException: Unexpected exception while enlisting XAConnection java.sql.SQLException: XA error: XAER_RMERR : A resource manager error has occured in the transaction branch start() failed on resource ''TestXAPool_1'': XAER_RMERR : A resource manager error has occured in the transaction branch
oracle.jdbc.xa.OracleXAException
at oracle.jdbc.xa.OracleXAResource.checkError (OracleXAResource.java:1017)
at oracle.jdbc.xa.client.OracleXAResource.start (OracleXAResource.java:227)
at weblogic.jdbc.wrapper.VendorXAResource.start (VendorXAResource.java:50)
at weblogic.jdbc.jta.DataSource.start (DataSource.java:629)
at weblogic.transaction.internal.XAServerResourceInfo.start (XAServerResourceInfo.java:1142)
at weblogic.transaction.internal.XAServerResourceInfo.xaStart (XAServerResourceInfo.java:1073)
at weblogic.transaction.internal.XAServerResourceInfo.enlist (XAServerResourceInfo.java:241)
at weblogic.transaction.internal.ServerTransactionImpl.enlistResource (ServerTransactionImpl.java:463)
at weblogic.jdbc.jta.DataSource.enlist(DataSource.java:1392)
at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist (DataSource.java:1334)
at weblogic
|