This class does not impose a reader or a writer preference ordering for lock access. Instead, all lock acquisition requests are processed in order, as follows:
Acquisition requests contend for entry using a ZooKeeper-ordered arrival policy. When the currently held lock is released, either the longest-waiting single writer will be assigned the write lock, or if there are a group of reader parties waiting longer than all waiting writer parties, then all readers in that group will be assigned the read lock.A party that attempts to acquire a read lock for the first time will block if either the write lock is held, or if there is a waiting writer party. The party will block until the oldest currently waiting writer party has acquired and released the write lock. If a waiting writer abandons its wait, it has been considered equivalent to an acquisition and release of the lock.
A party that attempts to acquire a write lock for the first time will block unless both the read and write locks are free. Note that, unlike in the concurrent {@link java.util.concurrent.locks.ReentrantReadWriteLock} version, all methods obey ZooKeeper-ordering to determine when a lock may be acquired.
Note: Downgrading a WriteLock to a ReadLock is possible on the same thread. To do so, acquire the write lock, then acquire the read lock on the same thread. Finally, release the write lock. However, upgrading from a ReadLock to a WriteLock is not possible without first releasing the ReadLock.
Note also that the write lock provides a {@link java.util.concurrent.locks.Condition}implementation that behaves the same way with respect to the write lock as the {@link java.util.concurrent.locks.Condition}implementation provided by {@link ReentrantZkLock#newCondition()}. This condition may only be used for the WriteLock. The ReadLock does not support {@link Condition}s.
Note: This implementation supports only {@code Integer.MAX_VALUE} number of write and read locks. Attempts toexceed this will cause integer overflow, resulting in potentially improper Lock state. @author Scott Fines @version 1.0 @see java.util.concurrent.locks.ReentrantReadWriteLock @deprecated Use {@link Locksmith} factories to create a different (internal) lock instance instead.
|
|
|
|
|
|
|
|