|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.objectweb.cjdbc.common.util.ReadPrioritaryFIFOWriteLock
Reader/Writer lock with write priority.
If a reader holds the lock, all incoming readers are allowed to acquire the
lock until a write arrives. A writer must wait for all current readers to
release the lock before acquiring it.
When a writer has the lock, everybody else is blocked.
When a writer release the lock, there is a writer priority so if another
writer is waiting it will have the lock even if it arrived later than
readers. Writers are prioritary against readers but all writers get the lock
in a FIFO order.
Field Summary | |
private int |
activeReaders
Threads executing read. |
private boolean |
activeWriter
Is there an active writer? |
private java.lang.Object |
readSync
|
private int |
waitingReaders
Threads not yet in read. |
private int |
waitingWriters
Threads not yet in write. |
private java.util.ArrayList |
writeWaitingQueue
|
Constructor Summary | |
ReadPrioritaryFIFOWriteLock()
Creates a new ReadPrioritaryFIFOWriteLock instance. |
Method Summary | |
void |
acquireRead()
Acquires the lock for a read. |
void |
acquireWrite()
Acquires the lock for a write. |
boolean |
isReadLocked()
Tests if the lock is currently held by at least one reader. |
boolean |
isWriteLocked()
Tests if the lock is currently held by a writer. |
void |
releaseRead()
Releases a lock previously acquired for reading. |
void |
releaseWrite()
Releases a lock previously acquired for writing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private int activeReaders
private boolean activeWriter
private int waitingReaders
private int waitingWriters
private java.lang.Object readSync
private java.util.ArrayList writeWaitingQueue
Constructor Detail |
public ReadPrioritaryFIFOWriteLock()
ReadPrioritaryFIFOWriteLock
instance.
Method Detail |
public void acquireRead() throws java.lang.InterruptedException
java.lang.InterruptedException
- if wait failed (the lock should remain in a
correct state)public void releaseRead()
public void acquireWrite() throws java.lang.InterruptedException
java.lang.InterruptedException
- if wait failed (the lock should remain in a
correct state)public void releaseWrite()
public final boolean isReadLocked()
true
if the lock is held by a readerpublic final boolean isWriteLocked()
true
if the lock is held by a writer
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |