Read-write lock in Java allows multiple threads to acquire a read lock provided no other thread simultaneously has a write lock on the same object. A thread may acquire a write lock if no other thread owns either a read lock or a write lock.
The logic for writing or implementing lock will be as follows:
Code:
readLock
Lock readLock()
Returns the lock used for reading.
Returns:
the lock used for reading.
writeLock
Lock writeLock()
Returns the lock used for writing.
Returns:
the lock used for writing.
Hope you will get some idea, how to set the lock.
Bookmarks