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

Transaction propagation in asynchronous ejb method call

我们有两个 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(){
     }

}

不在任何事务中的客户端调用MyStatelessSessionBean 的methodA。所有处理完成后,容器将启动多少个独立事务?

将启动 2 个事务。正如 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. This means, for example, that the semantics of the REQUIRED transaction attribute on an asynchronous method are exactly the same as REQUIRES_NEW.