public class StripedReadWriteLockSync extends java.lang.Object implements StripedReadWriteLock
BlockingCache
, where it has been in use
in highly concurrent production environments for years.
Based on the lock striping concept from Brian Goetz. See Java Concurrency in Practice 11.4.3Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_NUMBER_OF_MUTEXES
The default number of locks to use.
|
private ReadWriteLockSync[] |
mutexes |
private java.util.List<ReadWriteLockSync> |
mutexesAsList |
Constructor and Description |
---|
StripedReadWriteLockSync()
Constructs a striped mutex with the default 2048 stripes.
|
StripedReadWriteLockSync(int numberOfStripes)
Constructs a striped mutex with the default 2048 stripes.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<ReadWriteLockSync> |
getAllSyncs()
Returns all internal syncs
|
java.util.concurrent.locks.ReadWriteLock |
getLockForKey(java.lang.Object key)
Gets the RWL Stripe to use for a given key.
|
ReadWriteLockSync |
getSyncForKey(java.lang.Object key)
Gets the Sync Stripe to use for a given key.
|
public static final int DEFAULT_NUMBER_OF_MUTEXES
private final ReadWriteLockSync[] mutexes
private final java.util.List<ReadWriteLockSync> mutexesAsList
public StripedReadWriteLockSync()
public StripedReadWriteLockSync(int numberOfStripes)
numberOfStripes
- - must be a factor of twopublic ReadWriteLockSync getSyncForKey(java.lang.Object key)
getSyncForKey
in interface CacheLockProvider
key
- the keypublic java.util.concurrent.locks.ReadWriteLock getLockForKey(java.lang.Object key)
getLockForKey
in interface StripedReadWriteLock
key
- the keypublic java.util.List<ReadWriteLockSync> getAllSyncs()
getAllSyncs
in interface StripedReadWriteLock