java.lang.Object | |
↳ | com.microstrategy.utils.concurrent.WriterPreferenceReadWriteLock |
![]() |
A ReadWriteLock that prefers waiting writers over waiting readers when there is contention. This class is adapted from the versions described in CPJ, improving on the ones there a bit by segregating reader and writer wait queues, which is typically more efficient.
The locks are NOT reentrant. In particular, even though it may appear to usually work OK, a thread holding a read lock should not attempt to re-acquire it. Doing so risks lockouts when there are also waiting writers.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | WriterPreferenceReadWriteLock.ReaderLock | ||||||||||
class | WriterPreferenceReadWriteLock.Signaller | Reader and Writer requests are maintained in two different wait sets, by two different objects. | |||||||||
class | WriterPreferenceReadWriteLock.WriterLock |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
protected long | activeReaders_ | ||||||||||
protected Thread | activeWriter_ | ||||||||||
protected final WriterPreferenceReadWriteLock.ReaderLock | readerLock_ | ||||||||||
protected long | waitingReaders_ | ||||||||||
protected long | waitingWriters_ | ||||||||||
protected final WriterPreferenceReadWriteLock.WriterLock | writerLock_ |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WriterPreferenceReadWriteLock() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sync |
readLock()
get the readLock *
| ||||||||||
Sync |
writeLock()
get the writeLock *
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
boolean |
allowReader()
Override this method to change to reader preference *
| ||||||||||
synchronized void | cancelledWaitingReader() | ||||||||||
synchronized void | cancelledWaitingWriter() | ||||||||||
synchronized WriterPreferenceReadWriteLock.Signaller |
endRead()
Called upon termination of a read.
| ||||||||||
synchronized WriterPreferenceReadWriteLock.Signaller |
endWrite()
Called upon termination of a write.
| ||||||||||
synchronized boolean | startRead() | ||||||||||
synchronized boolean | startReadFromNewReader() | ||||||||||
synchronized boolean | startReadFromWaitingReader() | ||||||||||
synchronized boolean | startWrite() | ||||||||||
synchronized boolean | startWriteFromNewWriter() | ||||||||||
synchronized boolean | startWriteFromWaitingWriter() |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Override this method to change to reader preference *
Called upon termination of a read. Returns the object to signal to wake up a waiter, or null if no such
Called upon termination of a write. Returns the object to signal to wake up a waiter, or null if no such