异步 EJB 3.1 方法和事务

发布于 2024-12-08 12:50:44 字数 344 浏览 4 评论 0原文

我使用 @Asynchronous 注释编写了一个小测试来了解 EJB3.1 中的异步行为。看来:

如果该方法与调用者存在于同一个bean中,则

  1. Call不再是异步的。
  2. 如果异步方法中的事务被回滚,则调用者事务被标记为回滚;它可能是 1 的副作用。

但是,如果异步方法存在于另一个 bean 中,则该行为是预期的,即调用是异步的并且调用者事务是独立的(异步方法对于事务具有 REQUIRES_NEW 行为)。这让我感到困惑,因为为什么两种情况下的行为不一样。有人请澄清一下吗?

PS 环境 EJB 3.1、JBoss 6

I wrote a small test to understand asynchronized behavior in EJB3.1 using @Asynchronous annotation. It seems that:

If the method exist in the same bean as the caller,

  1. Call is no longer asynchronized.
  2. The caller transaction is marked for roll back, if the transaction in the asynchronous method is rolled back; its probably the side effect of 1.

However, if the asynchronous method exists in another bean, the behavior is expected i.e. call is asynchronous and the caller transaction is independent (async method have REQUIRES_NEW behavior for transaction). This is puzzling for me, as why the behavior is not the same in both cases. Would someone please clarify?

P.S. Environment EJB 3.1, JBoss 6

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一张白纸 2024-12-15 12:50:44

使用 this 关键字而不是使用 SessionContext#getBusinessObject(class) 调用该方法会导致这种情况。 (差异解释这里)

Calling the method using this keyword instead of using SessionContext#getBusinessObject(class) causes that. (the difference is explained here )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文