Distributed Transactions   «Prev  Next»

Lesson 6 Client-managed transactions
Objective Describe client-managed transactions.

Client-managed Transactions

As mentioned earlier, the three places where a transaction can be started and managed are the client, the bean, and the container.
Client-managed is when the client is not an EJB but is a non-bean program.

Transactions

Transactions have to be started (begin) and committed from the same thread using the same reference. Other entites (recoverable and transactioinal objects) can request the transaction to be rolled back. For example, if a database cannot save its state for some reason, it can request a rollback of the transaction.

Clients can start transactions

In the diagram below the transaction is started by the client and propagated to multiple transactional objects (EJB1and EJB2) and recoverable objects (Oracle, Sybase, and DB2 databases).

Client Transaction communicating with EJB1 and EJB2. EJB1 updates an Oracle and Sybase Database
Client Transaction communicating with EJB1 and EJB2. EJB1 updates an Oracle and Sybase Database

In order for the client to start transaction T1 it needs access to the transaction manager. This is available through JTA. Multiple beans and databases will be updated in a single transaction using two-phase commit.

Should clients manage transactions?

There are problems with clients managing their transactions.
  1. How does the client get access to the transaction manager? It needs to know the JTA interface. But what if the client is a web page or a visual basic program?
  2. How does the client know whether a transaction is required downstream? Should a client need to know how the service is provided?Should it know where the data is stored?
You will appreciate these problems if you consider that the client may be a web page or a visual basic program.
A thin-client application is one in which the server side is responsible for generating the user interface views into the application. The client side usually consists only of generic rendering software, i.e., a web browser.
If you have built web-based applications before, you are no doubt familiar with the thin-client architecture. Until recently, the burden of generating the user interface for your application on the server side was not too difficult. Two relatively recent developments, however, are now making the development and maintenance of your presentation layer components more challenging.

Serving different types of devices

The first new challenge relates to the ongoing proliferation of web-enabled devices. It seems as though anything that runs on electricity these days now has a web browser on it. These smart devices include cell phones, PDAs, and refrigerators. Websites re-designed for mobile screens, with sizes ranging from smartphones, netbooks, and tablets, to laptops, with a desktop screen shown for scale.
The mobile web, also known as mobile internet, refers to browser-based Internet services accessed from handheld mobile devices, such as smartphones or feature phones, through a mobile or other wireless network. In the past, the World Wide Web has been accessed via fixed-line services on laptops and desktop computers. However, the web is now more accessible by portable and wireless devices. An early 2010 ITU (International Telecommunication Union) report said that with current growth rates, web access by mobile devices will exceed web access from desktop computers.
In 2017 the number of mobile devices accessing the web exceeded the number of desktop devices.