mysql - @Never 事务属性非常慢

标签 mysql jakarta-ee transactions annotations glassfish

我已经编写了一种基准测试,用于评估事务属性的不同组合如何影响 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_Supported8.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/

相关文章:

mysql - 过滤特定列上按给定步长增加的行

mysql - 显式索引和隐式索引之间的区别?

java - 无状态状态在工作后是否被清除?

java - 如何编写一个或多或少充当容器的应用程序?

MySQL 事务 - 项目以相反的顺序插入

php - 如何编写一个函数来获得树结构的输出

mysql - 如果过去 24 小时内没有输入数据,则自动插入行

java - 如何使用 Java 监视来自/到 servlet 的 HTTP 请求和响应

java - 我想根据 Spring MVC 中的 Http Status 代码向 Http Response 添加 header

iOS CoreData 提交子事务但取消主事务