K
- the type of the keys by which locks are indexedpublic class StripedReadWriteLockImpl<K> extends java.lang.Object implements StripedReadWriteLock<K>
StripedReadWriteLock
implementation.Constructor and Description |
---|
StripedReadWriteLockImpl() |
Modifier and Type | Method and Description |
---|---|
boolean |
downgradeLock(K key) |
boolean |
isLockHeldByCurrentThread(K key) |
boolean |
isReadLockHeldByCurrentThread(K key) |
boolean |
isWriteLockHeldByCurrentThread(K key) |
void |
obtainLocks(java.util.Collection<K> readKeys,
java.util.Collection<K> writeKeys)
Multiple concurrent calls from different threads do not lock.
|
void |
obtainReadLocks(java.util.Collection<K> readKeys)
Multiple concurrent calls from different threads do not lock.
|
void |
obtainWriteLocks(java.util.Collection<K> writeKeys)
Multiple concurrent calls from different threads do not lock.
|
java.util.Set<K> |
readLocksHeldByCurrentThread() |
boolean |
releaseLock(K key) |
boolean |
releaseLocks(java.util.Collection<? extends K> keys) |
boolean |
releaseLocks(java.util.Collection<? extends K> readKeys,
java.util.Collection<? extends K> writeKeys) |
boolean |
releaseReadLock(K key) |
boolean |
releaseReadLocks(java.util.Collection<? extends K> readKeys) |
boolean |
releaseWriteLock(K key) |
boolean |
releaseWriteLocks(java.util.Collection<? extends K> writeKeys) |
protected boolean |
silentlyDowngradeLock(K key) |
protected boolean |
silentlyReleaseReadLock(K key) |
protected boolean |
silentlyReleaseWriteLock(K key) |
protected boolean |
tryToObtainReadLock(K key) |
protected boolean |
tryToObtainWriteLock(K key) |
void |
wait(K key)
Wait for the given lock to become available.
|
void |
wait(K key,
long milliseconds)
Wait for the given lock to become available.
|
void |
wait(K key,
long milliseconds,
int nanoseconds)
Wait for the given lock to become available.
|
java.util.Set<K> |
writeLocksHeldByCurrentThread() |
public java.util.Set<K> readLocksHeldByCurrentThread()
readLocksHeldByCurrentThread
in interface StripedReadWriteLockRelease<K>
public java.util.Set<K> writeLocksHeldByCurrentThread()
writeLocksHeldByCurrentThread
in interface StripedReadWriteLockRelease<K>
public final void obtainReadLocks(java.util.Collection<K> readKeys) throws java.lang.InterruptedException
StripedReadWriteLock
obtainReadLocks
in interface StripedReadWriteLock<K>
readKeys
- Keys for read locks to be obtainedjava.lang.InterruptedException
- The obtaining thread was interrupted before the locks could be
obtained.public final void obtainWriteLocks(java.util.Collection<K> writeKeys) throws java.lang.InterruptedException
StripedReadWriteLock
obtainWriteLocks
in interface StripedReadWriteLock<K>
writeKeys
- Keys for write locks to be obtainedjava.lang.InterruptedException
- The obtaining thread was interrupted before the locks could be
obtained.public final void obtainLocks(java.util.Collection<K> readKeys, java.util.Collection<K> writeKeys) throws java.lang.InterruptedException
StripedReadWriteLock
obtainLocks
in interface StripedReadWriteLock<K>
readKeys
- Keys for read locks to be obtainedwriteKeys
- Keys for write locks to be obtainedjava.lang.InterruptedException
- The obtaining thread was interrupted before the locks could be
obtained.public final boolean releaseReadLocks(java.util.Collection<? extends K> readKeys)
releaseReadLocks
in interface StripedReadWriteLockRelease<K>
public final boolean releaseWriteLocks(java.util.Collection<? extends K> writeKeys)
releaseWriteLocks
in interface StripedReadWriteLockRelease<K>
public boolean releaseLocks(java.util.Collection<? extends K> keys)
releaseLocks
in interface StripedReadWriteLockRelease<K>
public final boolean releaseLocks(java.util.Collection<? extends K> readKeys, java.util.Collection<? extends K> writeKeys)
releaseLocks
in interface StripedReadWriteLockRelease<K>
public final boolean releaseReadLock(K key)
releaseReadLock
in interface StripedReadWriteLockRelease<K>
public final boolean releaseWriteLock(K key)
releaseWriteLock
in interface StripedReadWriteLockRelease<K>
public final boolean downgradeLock(K key)
downgradeLock
in interface StripedReadWriteLockRelease<K>
public final boolean releaseLock(K key)
releaseLock
in interface StripedReadWriteLockRelease<K>
protected final boolean tryToObtainReadLock(K key)
protected final boolean tryToObtainWriteLock(K key)
protected final boolean silentlyReleaseReadLock(K key)
protected final boolean silentlyReleaseWriteLock(K key)
protected final boolean silentlyDowngradeLock(K key)
public boolean isLockHeldByCurrentThread(K key)
isLockHeldByCurrentThread
in interface StripedReadWriteLockRelease<K>
public boolean isReadLockHeldByCurrentThread(K key)
isReadLockHeldByCurrentThread
in interface StripedReadWriteLockRelease<K>
public boolean isWriteLockHeldByCurrentThread(K key)
isWriteLockHeldByCurrentThread
in interface StripedReadWriteLockRelease<K>
public void wait(K key) throws java.lang.InterruptedException
StripedReadWriteLock
wait
in interface StripedReadWriteLock<K>
key
- The key to the lock on which we wish to wait.java.lang.InterruptedException
- The waiting thread was interrupted before the lock could be
obtained.public void wait(K key, long milliseconds) throws java.lang.InterruptedException
StripedReadWriteLock
wait
in interface StripedReadWriteLock<K>
key
- The key to the lock on which we wish to wait.milliseconds
- The timeout in milliseconds to wait.java.lang.InterruptedException
- The waiting thread was interrupted before the lock could be
obtained.public void wait(K key, long milliseconds, int nanoseconds) throws java.lang.InterruptedException
StripedReadWriteLock
wait
in interface StripedReadWriteLock<K>
key
- The key to the lock on which we wish to wait.milliseconds
- The timeout component in milliseconds to wait.nanoseconds
- The timeout component in nanoseconds to wait.java.lang.InterruptedException
- The waiting thread was interrupted before the lock could be
obtained.