用于异步方法的默认EJB事务模式

用于异步方法的默认EJB事务模式

本文介绍了用于异步方法的默认EJB事务模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 当我在EJB中有一个 @Asynchronous 方法时,我没有指定 @TransactionAttribute ,那么容器如何处理事务边界呢?显然,它不能使用调用线程的事务,那么它是做什么的?

  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 transaction boundaries? Obviously, it can't use the calling thread's transaction, so what does it do?

同样的问题,但是关于TimerService触发的方法。

Same question, but regarding methods that are triggered by the TimerService.






编辑:我觉得我的表现不好。我已经知道默认模式是REQUIRED。因此,应该安全地假设这些方法将始终在事务中调用。但我的问题是,该交易的生命周期是什么样的?容器是否为每个调用创建一个新的事务?还是重新使用异步工作线程上的所有调用相同的事务?如果是后者,那么事务何时关闭?


I think I phrased that poorly. I already know that the default mode is 'REQUIRED'. So it should be safe to assume that those methods will always be called within a transaction. But my question is, what does that transaction's life-cycle look like? Does the container create a new transaction for each call? Or does it re-use the same transaction for all the calls on an asynchronous worker thread? If it's the latter, then when does the transaction get closed?

推荐答案

类似于MDB,事务由容器启动在您的 @Asynchronous @Schedule @Timeout 方法之前(和可用拦截器)实际上是在方法(和拦截器)完成之后调用和提交的。

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.

按照惯例,事务传播到所有方法中调用的所有bean,所有bean都是这些bean,递归地调用。当然,其他调用的bean可以通过指定其他 @TransactionAttribute 设置来更改方法调用的事务语义(比如说 REQUIRES_NEW ,或 NOT_SUPPORTED )。

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).

旁注,事务不会传播到具有 @TransactionManagement(BEAN)。在调用Bean管理事务bean之前的方法时,容器将永远暂停任何正在进行的事务。

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.

这篇关于用于异步方法的默认EJB事务模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:26