|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.concurrent.StripedReadWriteLockSync
public class StripedReadWriteLockSync
Provides a number of Sync which allow fine-grained concurrency. Rather than locking a cache or a store, the individual elements or constituent objects can be locked. This dramatically increases the possible concurrency.
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 fromBlockingCache
, 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
Field Summary | |
---|---|
static int |
DEFAULT_NUMBER_OF_MUTEXES
The default number of locks to use. |
Constructor Summary | |
---|---|
StripedReadWriteLockSync()
Constructs a striped mutex with the default 2048 stripes. |
|
StripedReadWriteLockSync(int numberOfStripes)
Constructs a striped mutex with the default 2048 stripes. |
Method Summary | |
---|---|
Sync[] |
getAndWriteLockAllSyncForKeys(long timeout,
Object... keys)
Gets and write lock the Sync Stripes to use for the given keys. |
Sync[] |
getAndWriteLockAllSyncForKeys(Object... keys)
Gets and write lock the Sync Stripes to use for the given keys. |
ReadWriteLockSync |
getSyncForKey(Object key)
Gets the Sync Stripe to use for a given key. |
void |
unlockWriteLockForAllKeys(Object... keys)
write unlock the Sync Stripes to use for the given keys. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_NUMBER_OF_MUTEXES
Constructor Detail |
---|
public StripedReadWriteLockSync()
public StripedReadWriteLockSync(int numberOfStripes)
numberOfStripes
- - must be a factor of twoMethod Detail |
---|
public ReadWriteLockSync getSyncForKey(Object key)
getSyncForKey
in interface CacheLockProvider
key
- the key
public Sync[] getAndWriteLockAllSyncForKeys(Object... keys)
getAndWriteLockAllSyncForKeys
in interface CacheLockProvider
keys
- the keys to lock and get syncs for
public Sync[] getAndWriteLockAllSyncForKeys(long timeout, Object... keys) throws TimeoutException
getAndWriteLockAllSyncForKeys
in interface CacheLockProvider
timeout
- amount of milliseconds before timeout occurskeys
- the keys to lock and get syncs for
TimeoutException
- thrown when locks could not be acquired within
specified timeout.public void unlockWriteLockForAllKeys(Object... keys)
unlockWriteLockForAllKeys
in interface CacheLockProvider
keys
- the keys to unlock
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |