事务处理Transactions Suspension的实现

 近期上了新项目ATG(Art Technology Group),Oracle把人家收购了,又要学习新的东西了.

ATG是基于Java的,Java以前有用过一部分,但是了解不多,都是最基础的,而且用的时候都是知其然而不知其所以然,这次在学习的过程中,接触了很多底层的讲述,直到一段代码的执行会出现了what happen和how and why.收获还是挺多的.

以前我就挺迷惑的,比如在Java中往数据库里insert一条记录,insert into test(id,value) values(id_sequence.next_val,'test'),至于事务怎么处理,底层发生了什么,没想过^^.

这次看文档,发现有个Transactions Suspension的概念,它解释了当插入一条记录时,会发生什么,以及为啥这么设计,贴来展示展示:

The solution is to use the JTA’s mechanism for suspending and resuming transactions. Suspending a
transaction dissociates the transaction from its thread, leaving the thread without a current transaction.
The transaction still exists and keeps track of the resources it has used so far, but any further work done by
the thread does not use that transaction.
After the transaction is suspended, the thread can create a transaction. Any further work done by the
thread, such as the generation of an ID, occurs in that new transaction.
The new transaction can end after the ID has been generated, thereby committing the changes made to
the ID counter. After ending this transaction, the thread again has no current transaction. The previously
suspended transaction can now be resumed, which means that the transaction is re-associated with the
original thread. The request can then continue using the same transaction and resources that it was using
before the ID generator was used.

 


The steps are as follows:
1. Suspend the current transaction before the ID generation.
2. Create a transaction to handle the ID generation.
3. End that transaction immediately after the ID generation
4. Resume the suspended transaction.
An application server can suspend and resume transactions through calls to the TransactionManager
object; individual applications should not perform these operations directly. Instead, applications should
use J2EE transaction demarcation facilities (described in the next section), and let the application server
manage the underlying mechanics.

如此看来,一条普通的sql语句,在后台也做了不少事情,有时候想想,底层的东西还真真挺好玩的。

你可能感兴趣的:(事务处理Transactions Suspension的实现)