我已经编写了一种基准测试,用于评估事务属性的不同组合如何影响 Java EE 程序的性能。基准测试从带有“X”注释的方法调用带有“Y”注释的方法。我的基准交易涵盖了银行转账的情况:
@Required @RequiresNew
theCallerMethod() -> updateAccount(Account acc)
@RequiresNew
-> updateOwner(Company c)
@RequiresNew
-> addLogEntry(Transfer t)
因此,在 callerMethod 事务的上下文中,容器必须暂停调用者的事务、开始新的事务、更新帐户、提交、切换到调用者的、暂停、开始新的事务、更新公司、提交、返回到调用方,暂停,启动另一个,添加日志条目,提交,然后返回到最终提交调用方事务的调用方方法。
当我发现最慢的调用来自@Never-annotated caller 方法时,我感到非常惊讶:为@Required -> @Required 场景执行上述 1000 次调用案例需要 5.71 秒,@Required -> @RequiresNew 6,35 秒,但 9,05 秒。 @Never -> @Not_Supported 和 8.95 秒。对于@Never -> @Supports。
@Never-contexts执行这么久可以吗?我的意思是我们甚至没有要暂停和恢复的事务。也许我错过了一些关于@Never 事务属性的常识?
我使用 Java EE 6、GlassFish 3、MySQL 5.1.69 InnoDB。
提前致谢。
最佳答案
I mean we even do not have a transaction to suspend and resume.
我不太确定。 ejb3.1是这样的specification说:
13.6.5 Handling of Methods that Run with “an unspecified transaction context”
The EJB specification does not prescribe how the container should manage the execution of a method with an unspecified transaction context the transaction semantics are left to the container implementation. Some techniques for how the container may choose to implement the execution of a method with an unspecified transaction context are as follows (the list is not inclusive of all possible strategies):
(以及其他可能性)
The container may treat each call of an instance to a resource manager as a single transaction (e.g. the container may set the auto-commit option on a JDBC connection).
关于mysql - @Never 事务属性非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22696680/