简体   繁体   English

异步ejb方法调用中的事务传播

[英]Transaction propagation in asynchronous ejb method call

We have two EJB session beans as given below; 我们有两个EJB会话bean,如下所示;

@Stateless
public class MyStatelessSessionBean{
      @EJB
       MyStatefulSessionBean statefulBean;
      public void methodA(){
          statefulBea.methodB();
      }
}

@Stateful
@ TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyStatefulSessionBean {
     @Asynchronous
     public void methodB(){
     }

}

A client, which is not in any in any transaction, invoke methodA of MyStatelessSessionBean. 客户端(不在任何事务中的任何事务中)调用MyStatelessSessionBean的methodA。 How many distict transactions will be started by container after all processing has completed ? 所有处理完成后,容器将启动多少个distict事务?

There will be 2 transactions started. 将开始2个交易。 As EJB 3.1 specification states in point 4.5.3: 正如EJB 3.1规范在4.5.3节中所述:

Client transaction context does not propagate with an asynchronous method invocation. 客户端事务上下文不会随异步方法调用一起传播。 From the Bean Developer's view, there is never a transaction context flowing in from the client. 从Bean Developer的角度来看,从来没有从客户端流入事务上下文。 This means, for example, that the semantics of the REQUIRED transaction attribute on an asynchronous method are exactly the same as REQUIRES_NEW. 这意味着,例如,异步方法上REQUIRED事务属性的语义与REQUIRES_NEW完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM