Week 99 — What is the `ReentrantReadWriteLock` class used for and how can it be used?
Question of the Week #99
What is the
ReentrantReadWriteLock
class used for and how can it be used?2 Replies
sample answer:
A
ReadWriteLock
consists of two locks: One for reading and one for writing. The goal of it is that multiple threads can hold the read-lock concurrently but only one can hold the write-lock and only while no thread is holding the read-lock. If a a thread owns the read lock, the write lock cannot be obtained by any other thread and vice-versa.
ReentrantReadWriteLock
is an implementation of the ReadWriteLock
interface that allows threads to obtain the lock even if they already have it.