Stateful UI Transactions

转载 2004年10月28日 13:07:00

Atomicity is one of the mandatory requirements of transactional applications. It is about executing all or nothing, hence most of the times application defines transaction boundaries like,
try {
} catch (Exception e) {

transaction – handle to transaction example, javax.transaction.UserTransaction or java.sql.Connection
This ensures that all tasks are either committed or rolled back, with the help of Transaction Service Provider.


Let us first understand the meaning of “Stateful UI Transactions” (I know the nomenclature is confusing enough, but I could not think of anything else).

What if, executing Task 3 (referring to the snippet above) requires manual interference/decision? (Operator wants to validate availability of seats before reserving one). One has to maintain the transaction state across user interactions. In a typical commercial application this would be a Web based GUI or a Windows based client.


There can be multiple solutions, database design should consider such a requirement and define flags to indicate transaction status. However, these solutions couple the requirement and data base design tightly.

Other solution that comes into mind is to store the Transaction handle in Session (Either HTTP or Custom Session) and reuse across user interaction to define transaction boundaries. This will not solve our problem, as a transaction handle is always a stateless wrapper over the actual transaction managed by transaction service provide (an application server) .

As recommended a thread of execution realizes a transaction. [Ref: Distributed Transaction Processing: The XA+ Specification Version 2 – page 9]. Most application servers hence implement transactions as a Thread Local Entity.

Now we need to ensure that, the thread that started transaction and executed Task 1 and 2, should execute Task 3 and commit /rollback the transaction.

The pattern models a logical TransactionContext (Object diagram - , nothing but a Java Thread that begins/commits/rolls back a transaction and executes transactional activities. Client threads assign tasks to the threads executing transactional activities.

Additional thoughts:

Further, application may require to LOCK the data while user interaction. This can be achieved using ISOLATION LEVELS set on connections used to access/modify the data.

Reference Implementation:

I have tried putting together this pattern as a portable framework ( Would like to receive comments on the same.

Dnyanesh Y. Sonavane

有状态、无状态(Stateful and Stateless)

我相信有不少人还不明白有状态和无状态(Stateful and Stateless)的概念,那么我们今天就来谈谈有状态和无状态,一方面不断总结提高自我,另一方面兼扫盲。这是Immutable不变模式的...
  • tantexian
  • tantexian
  • 2015年09月08日 11:28
  • 2014

EXTJS表格功能扩展 之 有状态表格StatefulGrid

1、状态保存服务 为了实现有状态表格,首选我们要提供状态保存服务,ExtJs已经提供了状态管理:Ext.state.Provider,为了让我们的代码更加优雅,我扩展了Provider。主要提供了布...
  • wwjgoodogo
  • wwjgoodogo
  • 2015年10月21日 20:49
  • 584

Stateful or stateless

HTTP is an example of a stateless protocol layered on top of TCP, a stateful protocol, which is la...
  • wwwpcstarcomcn
  • wwwpcstarcomcn
  • 2014年07月23日 15:10
  • 660

【keras】序贯Sequential模型实例之采用stateful LSTM的相同模型

采用stateful LSTM的相同模型: stateful LSTM的特点是,在处理过一个batch的训练数据后,其内部状态(记忆)会被作为下一个batch的训练数据的初始状态。状态LSTM使得我...
  • brucewong0516
  • brucewong0516
  • 2018年01月09日 00:33
  • 79

精通有状态vs无状态(Stateful vs Stateless)

精通有状态vs无状态(Stateful vs Stateless)—Immutable模式之姐妹篇Peter Wei我相信有不少人还不明白有状态和无状态(Stateful and Stateless)...
  • weigbo
  • weigbo
  • 2011年03月13日 20:13
  • 2614

Stateless Session Bean 与Stateful Session Bean 的比较

 两种Session Bean 都可以将系统逻辑放在方法之中执行。 不同的是: Stateful Session Bean 可以记录呼叫者的状态,因此一个使用者会有自己的一个实例。 Stateless...
  • totogogo
  • totogogo
  • 2007年07月13日 21:09
  • 4670

对EJB3 Stateless和Stateful的认识

有状态会话bean :每个用户有自己特有的一个实例,在用户的生存期内,bean保持了用户的信息,即“有状态”;一旦用户灭亡(调用结束或实例结束),bean的生命期也告结束。即每个用户最初都会得到一个初...
  • richard_2010
  • richard_2010
  • 2010年11月01日 17:43
  • 3781

Spring Stateful & Stateless bean

Spring Stateful & Stateless bean Spring bean 的范围,到底是用singleton 还是prototype呢? Spring官方文档,...
  • smithdoudou88
  • smithdoudou88
  • 2015年02月02日 14:36
  • 729


  • u012966023
  • u012966023
  • 2013年12月01日 23:12
  • 1371

hibernate4在执行sql时出现nested transactions not supported

环境:hibernate4  public void insertPaperContent(Integer author,String paperContent) { String sql = "...
  • zhanghe687
  • zhanghe687
  • 2016年05月18日 15:09
  • 3863
您举报文章:Stateful UI Transactions