java-design-patterns/reader-writer-lock
Anurag Agarwal 9c8ad4485b Resolves checkstyle errors for patterns starting with letter r (#1072)
* Reduces checkstyle errors in reactor

* Reduces checkstyle errors in reader-writer-lock

* Reduces checkstyle errors in repository

* Reduces checkstyle errors in resource-acquisition-is-initialization

* Reduces checkstyle errors in retry
2019-11-10 19:42:26 +02:00
..
2017-11-28 20:55:52 +02:00
2019-10-12 20:05:54 +03:00
2017-11-28 21:28:53 +02:00

layout, title, folder, permalink, categories, tags
layout title folder permalink categories tags
pattern Reader Writer Lock reader-writer-lock /patterns/reader-writer-lock/ Concurrency
Java
Difficulty-Intermediate
I/O
Performance

Intent:

Suppose we have a shared memory area with the basic constraints detailed above. It is possible to protect the shared data behind a mutual exclusion mutex, in which case no two threads can access the data at the same time. However, this solution is suboptimal, because it is possible that a reader R1 might have the lock, and then another reader R2 requests access. It would be foolish for R2 to wait until R1 was done before starting its own read operation; instead, R2 should start right away. This is the motivation for the Reader Writer Lock pattern.

alt text

Applicability:

Application need to increase the performance of resource synchronize for multiple thread, in particularly there are mixed read/write operations.

Real world examples:

Credits