Locked Object

Problem

How can you reduce the risk of a commit failure when modifying an object?

Context

You are developing a multi-user application that commits transactions on an application server. In your application, there is a substantial risk of a commit failure due to the probability of two clients modifying the same object during overlapping time intervals.

Forces

Solution

Obtain a write lock on an object before modifying it.

Resulting Context

You need to design your locking strategy carefully when obtaining multiple locks, so as not to lead to a deadlock situation where two separate processes are each waiting for a lock held by the other.

Rationale

This solution reduces the probability of commit failure by assuring that the locking process is the only client to be making updates to an object.

Related Patterns