Default EJB transaction mode for asynchronous methods?

后端 未结 2 1442
鱼传尺愫
鱼传尺愫 2021-02-01 14:58
  1. When I have an @Asynchronous method in an EJB, and I don\'t specify the @TransactionAttribute, then how exactly does the container handle the

相关标签:
2条回答
  • 2021-02-01 15:06

    From EJB 3.1 spec.

    4.5.3 Transactions

    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.

    0 讨论(0)
  • 2021-02-01 15:19

    Similar to an MDB the transaction is started by the container just before your @Asynchronous, @Schedule or @Timeout method (and applicable interceptors) is actually invoked and committed just after the method (and interceptors) completes.

    As per usual, the transaction propagates to all beans called in said method and all beans those beans call, recursively. Of course other beans invoked are welcome to change the transaction semantics of their method call via specifying other @TransactionAttribute settings (say REQUIRES_NEW, or NOT_SUPPORTED).

    Side note, transactions are never propagated to beans with @TransactionManagement(BEAN). The container will always suspend any transaction in progress before invoking a method on a Bean-Managed Transaction bean.

    0 讨论(0)
提交回复
热议问题