diff --git a/pom.xml b/pom.xml
index 89a197347..d2b02fdf7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@
intercepting-filterproducer-consumerpoison-pill
+ reader-writer-locklazy-loadingservice-layerspecification
diff --git a/reader-writer-lock/etc/reader-writer-lock.png b/reader-writer-lock/etc/reader-writer-lock.png
new file mode 100644
index 000000000..f7b600530
Binary files /dev/null and b/reader-writer-lock/etc/reader-writer-lock.png differ
diff --git a/reader-writer-lock/etc/reader-writer-lock.ucls b/reader-writer-lock/etc/reader-writer-lock.ucls
new file mode 100644
index 000000000..920904e76
--- /dev/null
+++ b/reader-writer-lock/etc/reader-writer-lock.ucls
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/reader-writer-lock/index.md b/reader-writer-lock/index.md
new file mode 100644
index 000000000..91d16892c
--- /dev/null
+++ b/reader-writer-lock/index.md
@@ -0,0 +1,29 @@
+---
+layout: pattern
+title: Reader Writer Lock
+folder: reader-writer-lock
+permalink: /patterns/reader-writer-lock/
+categories: Concurrent
+tags:
+- Java
+---
+
+**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.
+
+
+
+**Applicability:**
+
+Application need to increase the performance of resource synchronize for multiple thread, in particularly there are mixed read/write operations.
+
+**Real world examples:**
+
+* [Java Reader Writer Lock](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReadWriteLock.html)
+
+**Credits**
+
+* [Readers–writer lock](https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock)
+
+* [Readers–writers_problem](https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem)
\ No newline at end of file
diff --git a/reader-writer-lock/pom.xml b/reader-writer-lock/pom.xml
new file mode 100644
index 000000000..14b17011d
--- /dev/null
+++ b/reader-writer-lock/pom.xml
@@ -0,0 +1,24 @@
+
+
+ 4.0.0
+
+ com.iluwatar
+ java-design-patterns
+ 1.10.0-SNAPSHOT
+
+ reader-writer-lock
+
+
+ junit
+ junit
+ test
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+
diff --git a/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/App.java b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/App.java
new file mode 100644
index 000000000..1d02b6cad
--- /dev/null
+++ b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/App.java
@@ -0,0 +1,57 @@
+package com.iluwatar.reader.writer.lock;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+/**
+ *
+ * In a multiple thread applications, the threads may try to synchronize the shared resources
+ * regardless of read or write operation. It leads to a low performance especially in a "read more
+ * write less" system as indeed the read operations are thread-safe to another read operation.
+ *
+ * Reader writer lock is a synchronization primitive that try to resolve this problem. This pattern
+ * allows concurrent access for read-only operations, while write operations require exclusive
+ * access. This means that multiple threads can read the data in parallel but an exclusive lock is
+ * needed for writing or modifying data. When a writer is writing the data, all other writers or
+ * readers will be blocked until the writer is finished writing.
+ *
+ *
+ * This example use two mutex to demonstrate the concurrent access of multiple readers and
+ * writers.
+ *
+ *
+ * @author hongshuwei@gmail.com
+ */
+public class App {
+
+ /**
+ * Program entry point
+ *
+ * @param args command line args
+ */
+ public static void main(String[] args) {
+
+ ExecutorService executeService = Executors.newFixedThreadPool(1000);
+ ReaderWriterLock lock = new ReaderWriterLock();
+
+ // Start 10 readers
+ IntStream.range(0, 10)
+ .forEach(i -> executeService.submit(new Reader("Reader " + i, lock.readLock())));
+
+ // Start 10 writers
+ IntStream.range(0, 10)
+ .forEach(i -> executeService.submit(new Writer("Writer " + i, lock.writeLock())));
+ // In the system console, it can see that the read operations are executed concurrently while
+ // write operations are exclusive.
+ executeService.shutdown();
+ try {
+ executeService.awaitTermination(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ System.out.println("Error waiting for ExecutorService shutdown");
+ }
+
+ }
+
+}
diff --git a/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/Reader.java b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/Reader.java
new file mode 100644
index 000000000..5704fdf28
--- /dev/null
+++ b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/Reader.java
@@ -0,0 +1,40 @@
+package com.iluwatar.reader.writer.lock;
+
+import java.util.concurrent.locks.Lock;
+
+/**
+ * Reader class, read when it acquired the read lock
+ */
+public class Reader implements Runnable {
+
+ private Lock readLock;
+
+ private String name;
+
+ public Reader(String name, Lock readLock) {
+ this.name = name;
+ this.readLock = readLock;
+ }
+
+ @Override
+ public void run() {
+ readLock.lock();
+ try {
+ read();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * Simulate the read operation
+ *
+ */
+ public void read() throws InterruptedException {
+ System.out.println(name + " begin");
+ Thread.sleep(100);
+ System.out.println(name + " finish");
+ }
+}
diff --git a/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/ReaderWriterLock.java b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/ReaderWriterLock.java
new file mode 100644
index 000000000..b7edd149c
--- /dev/null
+++ b/reader-writer-lock/src/main/java/com/iluwatar/reader/writer/lock/ReaderWriterLock.java
@@ -0,0 +1,211 @@
+package com.iluwatar.reader.writer.lock;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+
+/**
+ * Class responsible for control the access for reader or writer
+ *
+ * Allows multiple readers to hold the lock at same time, but if any writer holds the lock then
+ * readers wait. If reader holds the lock then writer waits. This lock is not fair.
+ */
+public class ReaderWriterLock implements ReadWriteLock {
+
+
+ private Object readerMutex = new Object();
+
+ private int currentReaderCount = 0;
+
+ /**
+ * Global mutex is used to indicate that whether reader or writer gets the lock in the moment.
+ *
+ * 1. When it contains the reference of {@link readerLock}, it means that the lock is acquired by
+ * the reader, another reader can also do the read operation concurrently.
+ * 2. When it contains the reference of reference of {@link writerLock}, it means that the lock is
+ * acquired by the writer exclusively, no more reader or writer can get the lock.
+ *
+ * This is the most important field in this class to control the access for reader/writer.
+ */
+ private Set