Name

Pessimistic Concurrency Pattern

Goal

Allow multiple users to access shared resources in an environment where the possibility of collision is high, without forcing users to discard work (Figure B-19).

Pessimistic concurrency pattern
Figure B-19. Pessimistic concurrency pattern

Participants

Presentation tier

Provides a user interface to the end user.

Business delegate

Provides access to business logic.

Lock manager

Coordinates resource locking across multiple objects.

DAO

Provides access to the persistence layer.

Interactions

A client connects to the presentation tier and initiates a data edit session. The presentation tier contacts a business delegate to retrieve the data the user wants to edit. The business delegate contacts a lock manager object and requests a lock on the specific data the user wants to edit. If a lock is unavailable, the business delegate returns a message to the presentation tier. If a lock is available, the business delegate retrieves the data from a DAO and passes it back to the presentation tier. The user makes their edits and submits them back to the presentation tier. The presentation tier submits the changes to the business delegate, which submits them to the DAO. The DAO verifies the lock and writes the changes to the persistence layer. The business delegate then releases the lock.

Notes

Pessimistic concurrency prevents users from having their edits rejected by the system due to concurrent changes. ...

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.