Class ReentrantLock.WriteLock
- Enclosing class:
- ReentrantLock<T>
Represents a write lock which allows an object to hold the lock multiple
times. an object requesting a write lock blocks objects that request a
read lock.
-
Field Summary
Fields inherited from class de.aristaflow.adept2.util.locking.ReentrantLock.Lock
invalidated, lockCountManager, waitersForLock -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWriteLock(LockCountManager<? super T> lockCountManager) Creates a new write lock using the designatedLockCountManagerfor comparing objects. -
Method Summary
Modifier and TypeMethodDescriptionvoidProvides the designated object with a write lock.protected booleanGets whether a notification of waiting threads is required.Methods inherited from class de.aristaflow.adept2.util.locking.ReentrantLock.Lock
currentLockingObject, hasLock, invalidate, isLocked, lock, objectsWaitingToLock, unlock
-
Constructor Details
-
WriteLock
Creates a new write lock using the designatedLockCountManagerfor comparing objects.- Parameters:
lockCountManager- The manager counting locks for objects.
-
-
Method Details
-
lock
Provides the designated object with a write lock. The current thread will be blocked until the lock can be acquired or the timeout elapsed. Writers have priority, that is the currently active readers may proceed but successive readers will be blocked until no writer is active or waiting.Since the lock is reentrant, an object may acquire a lock multiple times. But it also has to release the lock per acquisition afterwards.
- Overrides:
lockin classReentrantLock<T>.Lock- Parameters:
object- The object that requests a write lock.origTimeout- The time to wait for the lock. A timeout <= 0 means to wait forever (or until the lock is granted).- Throws:
InterruptedException- If the thread is interrupted while waiting for the lock, anInterruptedExceptionwill be thrown.TimeoutException- If the designated timeout elapsed before the lock can be acquired, aTimeoutExceptionwill be thrown.
-
notificationRequired
protected boolean notificationRequired()Gets whether a notification of waiting threads is required. This depends on whether there are no more locks and whether there are threads waiting for the lock. This also respects readers that wait to lock.- Overrides:
notificationRequiredin classReentrantLock<T>.Lock- Returns:
- Whether a notification of waiting threads is required (no more locks and there are waiters for the lock).
-