Read-Write Lock
ReadWriteLock
maintains a pair of associated locks - one for reading and other for
writing operation. ReadLock in this pair may be held simultaneously
by multiple reader threads, so long as there are no writers.
WriteLock is exclusive.
It
has two methods :
1)
Lock readLock ()
2)
Lock writeLock ()
So,
you create an instance of ReadWriteLock and then obtain the two locks
using the 2 methods above. Then while reading, readLock is
locked/unlocked and while writing, writeLock is locked/unlocked.
|