异步 EJB 3.1 方法和事务
我使用 @Asynchronous
注释编写了一个小测试来了解 EJB3.1 中的异步行为。看来:
如果该方法与调用者存在于同一个bean中,则
- Call不再是异步的。
- 如果异步方法中的事务被回滚,则调用者事务被标记为回滚;它可能是 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,
- Call is no longer asynchronized.
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
this
关键字而不是使用SessionContext#getBusinessObject(class)
调用该方法会导致这种情况。 (差异解释这里)Calling the method using
this
keyword instead of usingSessionContext#getBusinessObject(class)
causes that. (the difference is explained here )