| java.lang.Object org.apache.commons.transaction.locking.GenericLock org.apache.commons.transaction.locking.ReadWriteLock
ReadWriteLock | public class ReadWriteLock extends GenericLock (Code) | | Convenience implementation of a read/write lock based on
GenericLock .
Reads are shared which means there can be any number of concurrent read
accesses allowed by this lock. Writes are exclusive. This means when there is
a write access no other access neither read nor write are allowed by this
lock. Additionally, writes are preferred over reads in order to avoid starvation. The idea
is that there are many readers, but few writers and if things work out bad the writer would
never be served at all. That's why it is preferred.
Calls to both
ReadWriteLock.acquireRead(Object,long) and
ReadWriteLock.acquireWrite(Object,long) are blocking and reentrant. Blocking
means they will wait if they can not acquire the descired access, reentrant means that a lock
request by a specific owner will always be compatible with other accesses on this lock by the
same owner. E.g. if you already have a lock for writing and you try to acquire write access
again you will not be blocked by this first lock, while others of course will be. This is the
natural way you already know from Java monitors and synchronized blocks.
version: $Id: ReadWriteLock.java 493628 2007-01-07 01:42:48Z joerg $ See Also: GenericLock |
Method Summary | |
public boolean | acquireRead(Object ownerId, long timeoutMSecs) Tries to acquire a blocking, reentrant read lock. | public boolean | acquireWrite(Object ownerId, long timeoutMSecs) Tries to acquire a blocking, reentrant write lock. |
NO_LOCK | final public static int NO_LOCK(Code) | | |
READ_LOCK | final public static int READ_LOCK(Code) | | |
WRITE_LOCK | final public static int WRITE_LOCK(Code) | | |
ReadWriteLock | public ReadWriteLock(Object resourceId, LoggerFacade logger)(Code) | | Creates a new read/write lock.
Parameters: resourceId - identifier for the resource associated to this lock Parameters: logger - generic logger used for all kind of debug logging |
acquireRead | public boolean acquireRead(Object ownerId, long timeoutMSecs) throws InterruptedException(Code) | | Tries to acquire a blocking, reentrant read lock. A read lock is
compatible with other read locks, but not with a write lock.
Parameters: ownerId - a unique id identifying the entity that wants to acquire acertain lock level on this lock Parameters: timeoutMSecs - if blocking is enabled by the wait parameterthis specifies the maximum wait time in milliseconds true if the lock actually was acquired throws: InterruptedException - when the thread waiting on this method is interrupted |
acquireWrite | public boolean acquireWrite(Object ownerId, long timeoutMSecs) throws InterruptedException(Code) | | Tries to acquire a blocking, reentrant write lock. A write lock is
incompatible with any another read or write lock and is thus exclusive.
Parameters: ownerId - a unique id identifying the entity that wants to acquire acertain lock level on this lock Parameters: timeoutMSecs - if blocking is enabled by the wait parameterthis specifies the maximum wait time in milliseconds true if the lock actually was acquired throws: InterruptedException - when the thread waiting on this method is interrupted |
Methods inherited from org.apache.commons.transaction.locking.GenericLock | public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public boolean equals(Object o)(Code)(Java Doc) protected Set getConflictingOwners(Object ownerId, int targetLockLevel, int compatibility)(Code)(Java Doc) protected Set getConflictingOwners(LockOwner myOwner, Collection ownersToTest)(Code)(Java Doc) protected Collection getConflictingWaiters(Object ownerId)(Code)(Java Doc) public int getLevelMaxLock()(Code)(Java Doc) public int getLevelMinLock()(Code)(Java Doc) public int getLockLevel(Object ownerId)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner()(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, boolean preferred)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(int supportLockLevel, boolean preferred)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, int supportLockLevel, boolean preferred)(Code)(Java Doc) public Object getOwner()(Code)(Java Doc) public Object getResourceId()(Code)(Java Doc) public boolean has(Object ownerId, int lockLevel)(Code)(Java Doc) public int hashCode()(Code)(Java Doc) protected boolean isCompatible(int targetLockLevel, int currentLockLevel)(Code)(Java Doc) protected void registerWaiter(LockOwner waitingOwner)(Code)(Java Doc) public synchronized boolean release(Object ownerId)(Code)(Java Doc) protected synchronized void setLockLevel(Object ownerId, LockOwner lock, int targetLockLevel, int compatibility, boolean intention)(Code)(Java Doc) public boolean test(Object ownerId, int targetLockLevel, int compatibility)(Code)(Java Doc) public synchronized String toString()(Code)(Java Doc) protected boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred)(Code)(Java Doc) protected synchronized boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred, boolean tryOnly)(Code)(Java Doc) protected void unregisterWaiter(LockOwner waitingOwner)(Code)(Java Doc)
|
|
|