Giovanni Far
Giovanni Far

Reputation: 1653

ReadWriteLock in Java

I want to be sure:

read lock:
If a thread is inside a read lock also another thread can enter in this read or in another read lock but any threads can enter in a write lock while 1 or more threads are in inside in a read lock.

write lock:
if a thread is inside in a write lock any threads can enter in a write lock or in a read lock.

Upvotes: 2

Views: 144

Answers (1)

user3392484
user3392484

Reputation: 1919

Read lock: other threads can also take a read lock, but no thread can hold a write lock.

Write lock: held by at most one thread; no threads can hold a read lock.

So: you can have one of:

  • no readers or writers
  • one or more readers and no writers
  • no readers and exactly one writer

Upvotes: 6

Related Questions