[本站首页] [管理页面] [写新日志] [退出]

朝为田舍郎,暮登天子堂,将相本无种,男儿当自强。
首页(178) Hibernate(10) JAVA(19) Web(15) Struts(7) 口水(9) Ides(18) 其它(51) AJAX(6) database(29) 
Blog信息

blog名称:四裤全输的小窝~~
日志总数:178
评论数量:699
留言数量:198
访问次数:1151570
建立时间:2005年10月29日

Blog内搜索



日志更新

谷歌地图定位偏移解决方法
【转】利用Windows内置的命令作端口
WIN2003服务器安全加固方案
[转]sql server 日期比较、日
MediaCoder 一般参数设置
[转]VMware中创建共享磁盘阵列的方
缓解vss共享文件夹的安全隐患问题(转)
Delphi 中调用JavaScript
微软的官方方法:延长Windows Se
cxGrid 过滤 排序后 取选中记录的

最新评论

回复:谷歌地图定位偏移解决方法
回复:谷歌地图定位偏移解决方法
回复:WIN2003服务器安全加固方案
回复:cxGrid 过滤 排序后 取选中
回复:TreeView 父节点 子节点 
回复:[转]Oracle Instead
回复:DWR 官方下载地址
ugg  boots
回复:cxGrid 过滤 排序后 取选中
回复:DWR 官方下载地址

友情链接

biglin's Blog
NoisyRam's Blog
Stone's Blog
Kevin 的小家
『知』治通鉴

留言板




[JAVA]分布式事务以及JTA编程
文章收藏,  网上资源,  软件技术,  电脑与网络 四裤全输 发表于 2006/6/10 10:01:26

转自:http://blog.donews.com/Ralph/archive/2004/11/18/174646.aspx1. DTP 和 Two - Phase Commit Protocol在分布式事务管理领域,X/Open的DTP模型是业界最被广泛接受分布式事务管理模型。几乎所有的事务处理产品,关系数据库以及消息产品都支持该DTP模型中定义的接口。下面是对DTP模型的一段描述:X/Open’s DTP model defines three components: application programs, resource managers(such as RDBMS), and a transaction manager. This model also specifies functional interfaces between application programs and the transaction manager (known as the TX interface), and between the transaction manager and the resource managers (the XA interface). With products complying to these interfaces, one can implement transactions with the two phase commit and recovery protocol to preserve atomicity of transactions.DTP 模型中有一个非常重要的模型,叫Two - Phase Commit Protocol。该协议作用于transaction manager和resource managers之间,保证所有的resource managers要么都commit, 要么都abort。具体的TPC protocol执行过程如下:The first phase of this protocol is the preparation phase, during which the transaction manager conducts a voting among all the resource managers registered for the target transaction. The transaction manager calls the prepare method on each resource manager, which will return a X_READONLY or XA_OK constant. The first value implies that the operations conducted on the target resource are read only, and there are no operations to be committed. The second value indicates that the resource manager is ready to commit the operations. In case the resource manager wants the transaction to be rolled back, it throws an appropriate XAException.The second phase is a commit or recover phase. Depending on whether all resource managers are ready for a commit or not, one of these phases will be invoked by the transaction manager. In case all the resource managers return a X_OK in the first phase, the transaction manager calls the commit method on each resource manager. Please note that the two phase protocol is not fool-proof, and the commit calls may throw appropriate XAException in return. In such a case, the transaction manager should initiate the recovery phase. In case the voting determines a rollback, the transaction calls the recover on each prepared resource manager. 2. Java Transaction Service Java 的事务实现构架遵循了DTP模型,主要有两部分组成:JTS(Java Transaction Service)和JTA(Java Transaction API)。 JTS主要规定了DTP模型中transaction manager的实现方式,而JTA则定义了application programs, transaction manager及resource manager之间的接口。 JTA可以分为三类, 分别为针对application接口,transaction manager接口和resource manager接口。 application接口包括:javax.transaction.Synchronization:An object intended to participate in a synchronization protocol with the transaction manager should implement this interface. This mechanism is based on the Observer pattern. This interface has two methods - beforeCompletion and afterCompletion to be called before starting and after completing, respectively, the two phase commit operation. transaction manager接口:javax.transaction.Status: Defines the flags for the status of a transaction. The javax.transaction.Transaction, javax.transaction.TransactionManager, and javax.transaction.UserTransaction interfaces provide a getStatus method that returns one of the above status flags.javax.transaction.Transaction: An object of this type is created for each global transaction. This interface provides methods for transaction completion(commit and rollback), resource enlistment (enlistResource) and delistment (delistResource), registration of synchronization objects (registerSynchronization), and query of status of the transaction (getStatus).javax.transaction.TransactionManager: This interface is implemented by the JTS and allows an application server to communicate with the transaction manager to demarcate transactions (begin, commit, rollback, suspend and resume), set the transaction for rollback (setRollbackOnly), get the associated Transaction object (getTransaction), set the transaction timeout interval (setTransactionTimeout) and query the status of the transaction (getStatus).javax.transaction.UserTransaction: This interface allows application components to manage transaction boundaries explicitly. This interface provides methods to begin and end transactions (begin, commit, and rollback), set the transaction for rollback (setRollbackOnly), set the transaction timeout interval (setTransactionTimeout), and get the status of the transaction (getStatus). The application server should provide an interface to create an object of this type.javax.transaction.xa.Xid: This interface is a Java mapping of the X/Open transaction identifier xid structure. The transaction manager uses an object of this type to associate a resource manager with a transaction.  resource manager接口:javax.transaction.xa.XAResource: This is a Java mapping of the X/Open XA interface, and is implemented by resource managers operating with the JTS. This interface provides methods to start (start) and end (end) work on behalf of a specified transaction, to prepare a transaction with the current resource (prepare), to end transactions with the current resource (commit, forget, recover, and rollback), to compare the current resource manager with another resource manager (isSameRM), and to get and set the transaction timeout (getTransactionTimeout, setTransactionTimeout).  3. 运用JTA 使用JTA进行分布式事务编程有两种方法,一种是通过javax.transaction.UserTransaction,另一种是通过javax.transaction.TransactionManager。但这两种方法之间的区别不是很清楚??? 运用javax.transaction.UserTransaction(以Weblogic6.1为例)://get UserTransaction//in websphere, jndi name is “java:comp/UserTransaction”UserTransaction  userTrans =   (UserTransaction)getInitialContext().lookup("javax.transaction.UserTransaction"); //begin transactionuserTrans.begin(); //transactional operations… //end transactionuserTrans.commit(); 运用javax.transaction.TransactionManager(以Weblogic6.1为例)://get UserTransactionUserTransaction  transManager =   (UserTransaction)getInitialContext().lookup("javax.transaction.TransactionManager"); //begin transactionTransaction trans = transManager.begin(); //transactional operations… //end transactiontransManager.commit();  Transaction对象封装了事务上下文,通过该对象的enlistResource(),delistResource()方法可以添加删除参与事务的resource manager, 通过registerSynchronization()方法可以注册监听对象。


阅读全文(4872) | 回复(0) | 编辑 | 精华


发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144767674 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号