Name
Optimistic Concurrency Pattern
Goal
To allow multiple users safe access to shared resources in environments in which there is minimal risk that two users will simultaneously edit the same data (Figure B-18).
Participants
- Presentation tier
Presents the end user with an interface to the application.
- Business delegate
Provides access to business logic.
- DAO
Provides access to the persistence layer.
Interactions
A user interacting with the presentation tier requests data to edit. The user performs edits and requests that the edits be saved by the system. The system checks to see if the data has been changed externally since the user began the edit process (possibly by retrieving the data a second time and comparing). If the data was changed externally, the system provides the user with an error message. If the data has not been changed, the system applies the user’s changes.
Notes
Optimistic concurrency works best in situations where there is little opportunity for collision between users, because when collision occurs, one user will have to rekey their data.
Get J2EE Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.