加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

数据库 – 如果我访问UserTransaction这是否意味着我使用2阶段提

发布时间:2021-03-30 19:45:02 所属栏目:MsSql教程 来源:网络整理
导读:UserTransaction ut =查找…. ut.beginTransaction(); saveToFooDB(); statelessEjb.transactionSupportedMethod(); //将内容保存到Foo DB saveToFooDB(); ut.commit(); 如果我正在做上述事情,那么我的理解是它不是XA事务,因为它不跨越多个资源(如DB加JMS)

UserTransaction ut =查找….
ut.beginTransaction();
saveToFooDB();
statelessEjb.transactionSupportedMethod(); //将内容保存到Foo DB
saveToFooDB();
ut.commit();

如果我正在做上述事情,那么我的理解是它不是XA事务,因为它不跨越多个资源(如DB加JMS).我的理解是否正确?

解决方法

数据源可以配置为两种:

> XA:这些数据源可以参与分发事务
> Local:也称为非XA,它们不能参与分布式事务

UserTransaction在JTA规范中定义,描述了如何协调分布式事务中的参与者.

然而,实现JTA规范的应用程序服务器可以自由地进行大量优化.其中之一是last-agent-optimization,它允许分布式事务中的最后一个参与者是Local.然后为最后的参与者进行常规提交.如果只有一个参与者,那么情况总是如此.

简而言之:

>如果您有多个参与者,则需要使用XA和2阶段提交
>如果只有一个参与者,大多数应用程序服务器都支持本地数据源,并且不使用完整的2阶段提交协议.

对于Glassfish,请参阅:

> last-agent-optimization
> configure JDBC data source

编辑

glassfish documentation的“交易范围”段解释得比我好.我猜这对所有应用服务器来说都是一样的.

A local transaction involves only one
non-XA resource and requires that all
participating application components
execute within one process. Local
transaction optimization is specific
to the resource manager and is
transparent to the Java EE
application.

In the Application Server,a JDBC
resource is non-XA if it meets any of
the following criteria:

  • In the JDBC connection pool configuration,the DataSource class
    does not implement the
    javax.sql.XADataSource interface.

  • The Global Transaction Support box is not checked,or the Resource
    Type setting does not exist or is not
    set to javax.sql.XADataSource.

A transaction remains local if the
following conditions remain true:

  • One and only one non-XA resource is used. If any additional non-XA
    resource is used,the transaction is
    aborted.
  • No transaction importing or exporting occurs.

Transactions that involve multiple
resources or multiple participant
processes are distributed or global
transactions. A global transaction can
involve one non-XA resource if last
agent optimization is enabled.
Otherwise,all resourced must be XA.
The use-last-agent-optimization
property is set to true by default.
For details about how to set this
property,see Configuring the
Transaction Service.

If only one XA resource is used in a transaction,one-phase commit occurs,otherwise the transaction is coordinated with a two-phase commit protocol.

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读