|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.cache.lock.StripedLock
@ThreadSafe public class StripedLock
A simple implementation of lock striping, using Fqns as the keys to lock on, primarily used to help make
CacheLoader
implemtations thread safe.
ReentrantReadWriteLock
instances, and using the Fqn
hashcodes to determine buckets.
Since buckets are used, it doesn't matter that the Fqn in question is not removed from the lock map when no longer in
use, since the Fqn is not referenced in this class. Rather, the hash code is used.
Constructor Summary | |
---|---|
StripedLock()
This constructor just calls StripedLock(int) with a default concurrency value of 20. |
|
StripedLock(int concurrency)
Creates a new StripedLock which uses a certain number of shared locks across all elements that need to be locked. |
Method Summary | |
---|---|
void |
acquireAllLocks(List<Fqn> fqns,
boolean exclusive)
Acquires locks on all fqns passed in. |
void |
acquireLock(Fqn fqn,
boolean exclusive)
Blocks until a lock is acquired. |
void |
releaseAllLocks(List<Fqn> fqns)
Releases locks on all fqns passed in. |
void |
releaseLock(Fqn fqn)
Releases a lock the caller may be holding. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StripedLock()
StripedLock(int)
with a default concurrency value of 20.
public StripedLock(int concurrency)
concurrency
- number of threads expected to use this class concurrently.Method Detail |
---|
public void acquireLock(Fqn fqn, boolean exclusive)
fqn
- the Fqn to lock onexclusive
- if true, a write (exclusive) lock is attempted, otherwise a read (shared) lock is used.public void releaseLock(Fqn fqn)
fqn
- the Fqn to releasepublic void releaseAllLocks(List<Fqn> fqns)
releaseLock(org.jboss.cache.Fqn)
. This method is idempotent.
fqns
- list of fqnsreleaseLock(org.jboss.cache.Fqn)
public void acquireAllLocks(List<Fqn> fqns, boolean exclusive)
acquireLock(org.jboss.cache.Fqn,boolean)
fqns
- list of fqnsexclusive
- whether locks are exclusive.acquireLock(org.jboss.cache.Fqn,boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |