The more stripes, the higher the concurrency. To be threadsafe, the instance of CacheLockProvider needs to be maintained for the entire life of the cache or store, so there is some added memory use.
Though a new class, this code has been refactored from 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.3
| Modifier and Type | Field and Description |
|---|---|
| public static final int | DEFAULT_NUMBER_OF_MUTEXES
The default number of locks to use. |
| private final ReadWriteLockSync[] | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | |
| public | StripedReadWriteLockSync(int
- must be a factor of two numberOfStripes)Constructs a striped mutex with the default 2048 stripes. |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: all internal syncsImplements net. |
| public ReadWriteLock | Returns: one of a limited number of RWLs.the key key)Implements net. |
| public ReadWriteLockSync | Returns: one of a limited number of Sync's.the key key)Implements net. |
| DEFAULT_NUMBER_OF_MUTEXES | back to summary |
|---|---|
| public static final int DEFAULT_NUMBER_OF_MUTEXES The default number of locks to use. Must be a power of 2. The choice of 2048 enables 2048 concurrent operations per cache or cache store, which should be enough for most uses. | |
| mutexes | back to summary |
|---|---|
| private final ReadWriteLockSync[] mutexes | |
| mutexesAsList | back to summary |
|---|---|
| private final List<ReadWriteLockSync> mutexesAsList | |
| StripedReadWriteLockSync | back to summary |
|---|---|
| public StripedReadWriteLockSync() Constructs a striped mutex with the default 2048 stripes. | |
| StripedReadWriteLockSync | back to summary |
|---|---|
| public StripedReadWriteLockSync(int numberOfStripes) Constructs a striped mutex with the default 2048 stripes. The number of stripes determines the number of concurrent operations per cache or cache store.
| |
| getAllSyncs | back to summary |
|---|---|
| public List Implements net. Returns all internal syncs
| |
| getLockForKey | back to summary |
|---|---|
| public ReadWriteLock getLockForKey(final Object key) Implements net. Gets the RWL Stripe to use for a given key. This lookup must always return the same RWL for a given key.
| |
| getSyncForKey | back to summary |
|---|---|
| public ReadWriteLockSync getSyncForKey(final Object key) Implements net. Gets the Sync Stripe to use for a given key. This lookup must always return the same Sync for a given key.
| |