|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.logicalcobwebs.concurrent.WriterPreferenceReadWriteLock
public class 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.
[ Introduction to this package. ]
Nested Class Summary | |
---|---|
protected class |
WriterPreferenceReadWriteLock.ReaderLock
|
protected class |
WriterPreferenceReadWriteLock.Signaller
Reader and Writer requests are maintained in two different wait sets, by two different objects. |
protected class |
WriterPreferenceReadWriteLock.WriterLock
|
Field Summary | |
---|---|
protected long |
activeReaders_
|
protected java.lang.Thread |
activeWriter_
|
protected WriterPreferenceReadWriteLock.ReaderLock |
readerLock_
|
protected long |
waitingReaders_
|
protected long |
waitingWriters_
|
protected WriterPreferenceReadWriteLock.WriterLock |
writerLock_
|
Constructor Summary | |
---|---|
WriterPreferenceReadWriteLock()
|
Method Summary | |
---|---|
protected boolean |
allowReader()
Override this method to change to reader preference |
protected void |
cancelledWaitingReader()
|
protected void |
cancelledWaitingWriter()
|
protected WriterPreferenceReadWriteLock.Signaller |
endRead()
Called upon termination of a read. |
protected WriterPreferenceReadWriteLock.Signaller |
endWrite()
Called upon termination of a write. |
Sync |
readLock()
get the readLock |
protected boolean |
startRead()
|
protected boolean |
startReadFromNewReader()
|
protected boolean |
startReadFromWaitingReader()
|
protected boolean |
startWrite()
|
protected boolean |
startWriteFromNewWriter()
|
protected boolean |
startWriteFromWaitingWriter()
|
Sync |
writeLock()
get the writeLock |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long activeReaders_
protected java.lang.Thread activeWriter_
protected long waitingReaders_
protected long waitingWriters_
protected final WriterPreferenceReadWriteLock.ReaderLock readerLock_
protected final WriterPreferenceReadWriteLock.WriterLock writerLock_
Constructor Detail |
---|
public WriterPreferenceReadWriteLock()
Method Detail |
---|
public Sync writeLock()
ReadWriteLock
writeLock
in interface ReadWriteLock
public Sync readLock()
ReadWriteLock
readLock
in interface ReadWriteLock
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 WriterPreferenceReadWriteLock.Signaller endRead()
protected WriterPreferenceReadWriteLock.Signaller endWrite()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |