J2EEOnline J2EE

Distributed Transactions   «Prev  Next»
Lesson 1

EJBs and Distributed Transactions

This lesson introduces you to distributed transactions.
In the first course in this series you programmed session beans. However, the course ignored transactions. In most industrial-strength applications based on EJBs, transactions are used to ensure data integrity. It is important that you understand how they work within the EJB architecture and that you know how to write beans that use them.


You will be introduced to the two Java packages, Java Transaction Services (JTS) and the Java Transaction API (JTA).
JTS is the underlying architecture that supports distributed transactions and JTA is the programmers' API used to access the services.

Managed transactions

You will be introduced to the three different ways a transaction can be managed. They are:
  1. Client-managed transactions--the client begins and commits the transaction
  2. Bean-managed transactions- the bean starts and controls the transaction
  3. Container-managed transactions-the EJB knows nothing about the transaction that the container is managing for it

Session synchronization

Session beans can be involved in transactions.
If they are container-managed, the session bean may still have a need to know or affect the outcome of a transaction. The SessionSynchronization object allows that session bean access to the transaction.


The final part of this module covers the exceptions that may be thrown by, and caught from, the transaction service. Managing transactions can be difficult. This information will make it easy for you to write programs that work correctly, no matter what happens to your transaction.

Distributed Multitiered Applications

The Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and the application components that make up a Java EE application are installed on various machines depending on the tier in the multitiered Java EE environment to which the application component belongs. Figure 2.1 shows two multitiered Java EE applications divided into the tiers described in the following list. The Java EE application parts shown in Figure 2.1 are presented in Java EE Components.
  1. Client-tier components run on the client machine.
  2. Web-tier components run on the Java EE server.
  3. Business-tier components run on the Java EE server.
  4. Enterprise information system (EIS)-tier software runs on the EIS server.

Although a Java EE application can consist of all tiers shown in Figure 2.1, Java EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations: client machines, the Java EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client-and-server model by placing a multithreaded application server between the client application and back-end storage.

Multitiered Applications
Figure 21 Multitiered Applications