public class ReadWriteLock extends GenericLock
GenericLock
.
acquireRead(Object, long)
and
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.GenericLock
GenericLock.LockOwner
Modifier and Type | Field and Description |
---|---|
static int |
NO_LOCK |
static int |
READ_LOCK |
static int |
WRITE_LOCK |
logger, owners, resourceId, waiters, waitingOwners
COMPATIBILITY_NONE, COMPATIBILITY_REENTRANT, COMPATIBILITY_REENTRANT_AND_SUPPORT, COMPATIBILITY_SUPPORT
Constructor and Description |
---|
ReadWriteLock(Object resourceId,
LoggerFacade logger)
Creates a new read/write lock.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquireRead(Object ownerId,
long timeoutMSecs)
Tries to acquire a blocking, reentrant read lock.
|
boolean |
acquireWrite(Object ownerId,
long timeoutMSecs)
Tries to acquire a blocking, reentrant write lock.
|
acquire, acquire, acquire, acquire, equals, getConflictingOwners, getConflictingOwners, getConflictingWaiters, getLevelMaxLock, getLevelMinLock, getLockLevel, getMaxLevelOwner, getMaxLevelOwner, getMaxLevelOwner, getMaxLevelOwner, getOwner, getResourceId, has, hashCode, isCompatible, registerWaiter, release, setLockLevel, test, toString, tryLock, tryLock, unregisterWaiter
public static final int NO_LOCK
public static final int READ_LOCK
public static final int WRITE_LOCK
public ReadWriteLock(Object resourceId, LoggerFacade logger)
resourceId
- identifier for the resource associated to this locklogger
- generic logger used for all kind of debug loggingpublic boolean acquireRead(Object ownerId, long timeoutMSecs) throws InterruptedException
ownerId
- a unique id identifying the entity that wants to acquire a
certain lock level on this locktimeoutMSecs
- if blocking is enabled by the wait
parameter
this specifies the maximum wait time in millisecondstrue
if the lock actually was acquiredInterruptedException
- when the thread waiting on this method is interruptedpublic boolean acquireWrite(Object ownerId, long timeoutMSecs) throws InterruptedException
ownerId
- a unique id identifying the entity that wants to acquire a
certain lock level on this locktimeoutMSecs
- if blocking is enabled by the wait
parameter
this specifies the maximum wait time in millisecondstrue
if the lock actually was acquiredInterruptedException
- when the thread waiting on this method is interruptedCopyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.