事务处理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语句,在后台也做了不少事情,有时候想想,底层的东西还真真挺好玩的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值