|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.triactive.jdo.util.ReadWriteLock
A simple read-write lock implementation. Multiple threads may lock using readLock(), only one can lock using writeLock(). The caller is responsible for coding a try-finally that ensures unlock() is called for every readLock() and writeLock() call.
A ReadWriteLock is recursive; with one exception, a thread can re-lock an object it already has locked. Multiple read locks can be acquired by the same thread, as can multiple write locks. The exception however is that a write lock cannot be acquired when a read lock is already held (to allow this would cause deadlocks).
Successive lock calls from the same thread must be matched by an equal number of unlock() calls.
Constructor Summary | |
ReadWriteLock()
Constructs read-write lock. |
Method Summary | |
void |
readLock()
Acquire a read lock. |
java.lang.String |
toString()
|
void |
unlock()
Release a read or write lock. |
void |
writeLock()
Acquire a write lock. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ReadWriteLock()
Method Detail |
public void readLock() throws java.lang.InterruptedException
If the calling thread already owns a write lock for the object a read lock is immediately acquired.
java.lang.InterruptedException
- If the thread is interrupted while attempting to acquire the lock.public void writeLock() throws java.lang.InterruptedException
This method cannot be called if the thread already owns a read lock on
the same ReadWriteLock object, otherwise an
IllegalStateException
is thrown.
java.lang.IllegalStateException
- If the thread already holds a read lock on the same object.
java.lang.InterruptedException
- If the thread is interrupted while attempting to acquire the lock.public void unlock()
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |