@ThreadSafe public class StripedLock extends Object
CacheLoader
implemtations thread safe.
Backed by a set of 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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.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)
Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.