J2EE Locking Strategies

It often seems that one of the great mysteries in EJB development is the selection of an appropriate locking policy that meets both performance and data integrity requirements. This document attempts to demystify this area and allow you to choose the right strategy for your application.

Data Isolation

This section describes the different isolation levels systems can exhibit and the their impact on the throughput of concurrent systems.

Using Database Locking

Many systems choose not to perform locking in the Application Server, but instead use the mechanisms built into the underlying database systems. This section describes the different solutions implemented by different database platforms, and how they can be used from inside the Application Server.

Entity EJB Locking

This section covers the different locking strategies used by J2EE Application Servers to control concurrent access to Entity EJBs. It also covers configuring the JBoss server to use the different strategies.

Using BMP Entities

This section describes the interactions between the EJB locking strategies in the Application Server and the locking strategies provided by a database. It highlights the issues that should be considered by developers writing Entities using Bean Managed Persistence and illustrates the SQL needed to ensure the global isolation level is preserved.

Using CMP Entities

With Container Managed Persistence, the EJB container is responsible for ensuring the locking policy configured in the Application Server is correctly maintained by the SQL statements executed. This section describes how to configure CMP/JBoss to maintain the desired isolation level.

Optimistic Web Transactions

The very nature of Web applications requires careful consideration of locking policies for operations that require multiple page requests. This section illustrates the issues with Web interactions and how optimisitic concurrency controls can be used to ensure data integrity.