org.modeshape.jcr.value.binary
Class NamedLocks
java.lang.Object
org.modeshape.jcr.value.binary.NamedLocks
public class NamedLocks
- extends Object
A utility class that represents a set of named locks, allowing callers to atomically obtain a lock with a given name. Locks are
released as normal. This class uses reference counts to remove locks only when a named lock is no longer being used.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NamedLocks
public NamedLocks()
writeLock
public Lock writeLock(String name)
- Obtain a write lock for the supplied name. When this method returns, the current thread will have obtained the lock.
Therefore, there is no need to call any of the lock methods (e.g.,
NamedLocks.WrappedLock.lock()
, NamedLocks.WrappedLock.lockInterruptibly()
,
NamedLocks.WrappedLock.tryLock()
or NamedLocks.WrappedLock.tryLock(long, TimeUnit)
), as those methods will immediately return.
- Parameters:
name
- the name of the lock
- Returns:
- the lock held by the current thread; never null
readLock
public Lock readLock(String name)
- Obtain a read lock for the supplied name. When this method returns, the current thread will have obtained the lock.
Therefore, there is no need to call any of the lock methods (e.g.,
NamedLocks.WrappedLock.lock()
, NamedLocks.WrappedLock.lockInterruptibly()
,
NamedLocks.WrappedLock.tryLock()
or NamedLocks.WrappedLock.tryLock(long, TimeUnit)
), as those methods will immediately return.
- Parameters:
name
- the name of the lock
- Returns:
- the lock held by the current thread; never null
lock
protected final Lock lock(String name,
boolean writeLock)
unlock
protected void unlock(NamedLocks.NamedLock namedLock,
Lock rawLock)
size
public int size()
- Get the number of named locks.
- Returns:
- the number of named locks; never negative
Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.