public class ReadWriteLockWithUpgrade extends Object implements ReadWriteLock
This class is similar to PreferredWriterReadWriteLock except that the read lock is upgradable to write lock. I.e., when a user calls upgradeLock(), it will release the read lock, wait for all the read locks to clear and obtain a write lock afterwards. In particular, the write lock is obtained with priority to prevent deadlock situation. The current design is based in part from Doug Lea's PreferredWriterReadWriteLock.
Note that the pre-requisite to use upgrade lock is the pre-existing of a read lock. Otherwise, a RuntimeException will be thrown.
Also note that currently lock can only be obtained through attempt
api with specified timeout instead acquire
is not supported.
Modifier and Type | Class and Description |
---|---|
protected class |
ReadWriteLockWithUpgrade.ReaderLock |
protected class |
ReadWriteLockWithUpgrade.WriterLock |
Modifier and Type | Field and Description |
---|---|
protected Thread |
activeWriter_ |
protected static Object |
dummy_ |
protected static org.apache.commons.logging.Log |
log_ |
protected ReadWriteLockWithUpgrade.ReaderLock |
readerLock_ |
protected static Map<ReadWriteLock,Object> |
upgraderLocal_ |
protected ReadWriteLockWithUpgrade.WriterLock |
writerLock_ |
Constructor and Description |
---|
ReadWriteLockWithUpgrade() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowReader()
Override this method to change to reader preference *
|
protected void |
cancelledWaitingReader() |
protected void |
cancelledWaitingWriter() |
protected Lock |
changeLock() |
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller |
endRead()
Called upon termination of a read.
|
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller |
endWrite()
Called upon termination of a write.
|
Lock |
readLock() |
protected boolean |
startRead() |
protected boolean |
startReadFromNewReader() |
protected boolean |
startReadFromWaitingReader() |
protected boolean |
startWrite() |
protected boolean |
startWriteFromNewWriter() |
protected boolean |
startWriteFromWaitingWriter() |
String |
toString() |
Lock |
upgradeLockAttempt(long msecs)
Attempt to obtain an upgrade to writer lock.
|
Lock |
writeLock() |
protected Thread activeWriter_
protected static final Map<ReadWriteLock,Object> upgraderLocal_
protected static final Object dummy_
protected final ReadWriteLockWithUpgrade.ReaderLock readerLock_
protected final ReadWriteLockWithUpgrade.WriterLock writerLock_
protected static final org.apache.commons.logging.Log log_
public Lock writeLock()
writeLock
in interface ReadWriteLock
public Lock readLock()
readLock
in interface ReadWriteLock
public Lock upgradeLockAttempt(long msecs) throws UpgradeException
msecs
- Time to wait in millisecons.UpgradeException
protected Lock changeLock()
protected void cancelledWaitingReader()
protected void cancelledWaitingWriter()
protected boolean allowReader()
protected boolean startRead()
protected boolean startWrite()
protected boolean startReadFromNewReader()
protected boolean startWriteFromNewWriter()
protected boolean startReadFromWaitingReader()
protected boolean startWriteFromWaitingWriter()
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller endRead()
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller endWrite()
Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.