public class StripedReadWriteLockSync extends Object implements StripedReadWriteLock
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 |
---|---|
static int |
DEFAULT_NUMBER_OF_MUTEXES
The default number of locks to use.
|
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 |
---|---|
List<ReadWriteLockSync> |
getAllSyncs()
Returns all internal syncs
|
ReadWriteLock |
getLockForKey(Object key)
Gets the RWL Stripe to use for a given key.
|
ReadWriteLockSync |
getSyncForKey(Object key)
Gets the Sync Stripe to use for a given key.
|
public static final int DEFAULT_NUMBER_OF_MUTEXES
The choice of 2048 enables 2048 concurrent operations per cache or cache store, which should be enough for most uses.
public StripedReadWriteLockSync()
public StripedReadWriteLockSync(int numberOfStripes)
The number of stripes determines the number of concurrent operations per cache or cache store.
numberOfStripes
- - must be a factor of twopublic ReadWriteLockSync getSyncForKey(Object key)
This lookup must always return the same Sync for a given key.
getSyncForKey
in interface CacheLockProvider
key
- the keypublic ReadWriteLock getLockForKey(Object key)
This lookup must always return the same RWL for a given key.
getLockForKey
in interface StripedReadWriteLock
key
- the keypublic List<ReadWriteLockSync> getAllSyncs()
getAllSyncs
in interface StripedReadWriteLock
Copyright © 2003–2015 Terracotta, Inc.. All rights reserved.