暂停交易是什么意思?
what does suspending a transaction means?
如果我们使用传播 Requires_new,那么它会暂停现有事务并创建一个新事务。那么suspends a 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.
要了解 Spring @Transaction API 的工作原理,我们必须查看 transaction propagation mechanism.
Spring 托管事务具有物理和逻辑事务,具体取决于配置。
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.
当 transaction
为 suspended
时,它会一直等待,直到可以从中断处继续。这意味着,在 transaction
为 suspended
时发生的更改不是相同 atomic unit
的一部分。换句话说,transaction
在suspended
时发生的事情不会是rolled back
,如果suspended transaction
(在它复活后)fails to commit
.
Spring 事务不会公开任何 API
供开发人员直接控制,除了事务配置。但是,如果您使用 JTA 来管理事务,那么您可以调用 suspend
和 resume
方法,如下所示:
Transaction tobj = TransactionManager.suspend();
..
TransactionManager.resume(tobj);
希望对您有所帮助!
如果我们使用传播 Requires_new,那么它会暂停现有事务并创建一个新事务。那么suspends a 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.
要了解 Spring @Transaction API 的工作原理,我们必须查看 transaction propagation mechanism.
Spring 托管事务具有物理和逻辑事务,具体取决于配置。
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 backindependently
. Here theouter transaction
is not affected by aninner transaction
’s rollback status.
当 transaction
为 suspended
时,它会一直等待,直到可以从中断处继续。这意味着,在 transaction
为 suspended
时发生的更改不是相同 atomic unit
的一部分。换句话说,transaction
在suspended
时发生的事情不会是rolled back
,如果suspended transaction
(在它复活后)fails to commit
.
Spring 事务不会公开任何 API
供开发人员直接控制,除了事务配置。但是,如果您使用 JTA 来管理事务,那么您可以调用 suspend
和 resume
方法,如下所示:
Transaction tobj = TransactionManager.suspend();
..
TransactionManager.resume(tobj);
希望对您有所帮助!