Strategized Locking

Learn about the strategized locking pattern.

The idea behind the strategized locking is to change the locking strategy during run or compile time. Let’s assume we have a component used in a different environment. Sometimes we want to lock it, unlock it, or use a shared lock. How can this be done? Recall the strategy pattern definition:

Note: Define a family of algorithms, encapsulate each one, and make them interchangeable.

Here, the only change is that we use different locking strategies instead of algorithms.

Strategized locking:

  • Makes it possible to use different locking strategies as interchangeable components.
  • Is the application of the strategy pattern to locking.

Strategized locking can be configured at run or at compile time. Let’s have a look at them.

Strategized locking runtime

Get hands-on with 1200+ tech skills courses.