简体   繁体   English

JTA事务:如果发生异常但未在事务上调用回滚,该怎么办?

[英]JTA Transaction: What happens if an exception happens but rollback is not called on the transaction?

We have some third party code wherein they do the following 我们有一些第三方代码,其中他们执行以下操作

  1. List item 项目清单

    Create a User Transaction eg 创建一个用户交易,例如

      txn = (UserTransaction)ctx.lookup( "UserTransaction" ); txn.begin( ); 
  2. Do some work persisting to the database (via JPA) to a MySQL database 做一些工作(通过JPA)持久化到数据库(通过JPA)到MySQL数据库

  3. txn.commit()

They have Exception blocks but NONE of them call txn.rollback . 它们具有Exception块,但没有一个调用txn.rollback Good coding practice says they NEED to call rollback if an exception occurs but my question is If the txn is not committed, and an exception occurs what is the negative effect of them NOT calling rollback? 良好的编码实践表明,如果发生异常,则需要调用回滚,但是我的问题是,如果未提交txn且发生异常,则不调用回滚的负面影响是什么?

The transaction stays active, until you either commit() or rollback() it. 事务保持活动状态,直到您对它进行commit()rollback() It will continue to hold locks and you may end up blocking your application (database, actually). 它将继续保持锁定状态,您最终可能会阻塞应用程序(实际上是数据库)。

IMO JTA事务最终应超时(基于set或默认transactionTimeout),并应自动回滚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM