问题描述
UserTransaction ut = lookup ....
ut.beginTransaction();
saveToFooDB();
statelessEjb.transactionSupportedMethod(); // save something to the Foo DB
saveToFooDB();
ut.commit();
如果我在做上述操作,我的理解是,它不是一个XA事务,因为它不跨越多个资源(如DB加JMS)。
数据源可以配置两种类型:
- XA :这些数据源可以参与分发交易
- -XA,他们不能参与分布式事务
UserTransaction
然而,实现JTA规范的应用程序服务器可以自由地进行大量的优化。其中之一是 last-agent-optimization
,它允许分布式事务中的最后一个参与者 Local 。然后对最后的参与者进行定期提交。
总之:
- 如果您有多个参与者,则需要使用XA和2阶段提交
- 如果只有一个参与者,则大多数应用程序服务器支持本地数据源,并且不使用完整-blow 2阶段提交协议。
对于Glassfish,请参阅:
EDIT b $ b
glassfish的段落transaction scope比我更好地解释它。
UserTransaction ut=lookup.... ut.beginTransaction(); saveToFooDB(); statelessEjb.transactionSupportedMethod(); //saves something to the Foo DB saveToFooDB(); ut.commit();
If i was doing the above then my understanding is that it is not an XA transaction as it doesn't span across multiple resources (like DB plus JMS). Is my understanding correct?
Data source can be configured of two kinds:
- XA: these datasource can participate in distribute transactions
- Local: also called non-XA, they can not participate in a distributed transaction
The UserTransaction
is defined in the JTA specification which describe how to coordinate the participant in a distributed transaction.
The application server which implements the JTA specification is however free to do a lot of optimizations. One of them is the last-agent-optimization
, which allows the last participant in the distributed transaction to be Local. A regular commit is then done for the last participants. If there is only one participant then it's always the case.
In short:
- if you have more than one participant, XA and 2 phase commit need to be used
- if there is only one participant, most application server support local data source and do not use the full-blow 2 phase commit protocol.
For Glassfish see:
EDIT
Paragraph "transaction scope" of glassfish documentation explains it better than me. I guess it's the same for all application server.
这篇关于如果我访问UserTransaction这是否意味着我使用2阶段提交或XA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!