暂停交易是什么意思? [英] what does suspending a transaction means?

查看:48
本文介绍了暂停交易是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们使用 Propagation Requires_new 那么它会挂起现有事务并创建一个新事务.那么暂停交易是什么意思?暂停的交易会怎样?幕后到底发生了什么?

更新

被挂起的事务持有的资源怎么办?

解决方案

首先,这里的问题是线程的重复:

<块引用>

PROPAGATION_REQUIRES_NEW 使用完全独立的事务对于每个受影响的交易范围.底层物理事务不同,因此可以提交或回滚独立.这里外部交易不受内部事务的回滚状态.

当一个 transaction挂起 时,它会等待直到它可以从停止的地方开始.这意味着,在 transaction 处于 suspended 时发生的更改不是同一 atomic unit 的一部分.换句话说,在transactionsuspend时发生的事情不会被rollback,如果suspended transaction> (恢复后)提交失败.

Spring 事务除了事务配置外,不公开任何 API 供开发人员直接控制.但是,如果您使用 JTA 来管理事务,那么您可以调用 suspendresume 方法,如下所示:

Transaction tobj = TransactionManager.suspend();..TransactionManager.resume(tobj);

希望对你有帮助!

If we are using Propagation Requires_new then it suspends existing transaction and creates a new transaction. So what does it mean to suspends a transaction? what happens to the suspended transaction? what exactly happens behind the scene?

update

what happens to the resource held by suspended transaction?

解决方案

First of all the question here is a duplication of the thread: How does transaction suspension work in Spring?. However, I will try to answer this in a different way.

To understand the working of Spring @Transaction API, we must look inside the transaction propagation mechanism.

Spring managed transaction has physical and logical transactions depending upon the configuration.

PROPAGATION_REQUIRES_NEW uses a completely independent transaction for each affected transaction scope. The underlying physical transactions are different and hence can commit or roll back independently. Here the outer transaction is not affected by an inner transaction’s rollback status.

When a transaction is suspended, it waits until it can pick up where it left off. This means, the changes that happened while the transaction is suspended are NOT part of the same atomic unit. In other words, the things that happened while the transaction is suspended won’t be rolled back if the suspended transaction (after it comes back to life) fails to commit.

Spring transaction does not expose any API for developers to control this directly, other than the transaction configurations. However if you are using JTA to manage transaction then you can call the suspend and resume methods as below:

Transaction tobj = TransactionManager.suspend();
..
TransactionManager.resume(tobj);

I hope this helps you!

这篇关于暂停交易是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆