com.antiaction.critical
Class RWLock

java.lang.Object
  |
  +--com.antiaction.critical.RWLock

public class RWLock
extends java.lang.Object

RWLock implements simultanious reads and exclusive writes. Based on an implementation by Scott Oaks & Henry Wong. Java Threads ISBN 1-56592-418-5.

This class allows multiple threads read access to data simultaniously. Write access is only granted for one thread at a time, with no read access simultaniously. Internal Vector used to coordinate access.

This should be a very robust implementation.

In depth coverage of the subject can be found in the afore mentioned book.

Version:
1.00
Author:
Nicholas Clarke

Constructor Summary
RWLock()
          Initialize object for use.
 
Method Summary
 void lockRead()
          Obtain a read lock, blocks until access is granted.
 void lockWrite()
          Obtain a write lock, blocks until exclusive access can be granted.
 void unlock()
          Decreases the nest count, if zero the lock is released.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RWLock

public RWLock()
Initialize object for use.
Method Detail

lockRead

public void lockRead()
Obtain a read lock, blocks until access is granted.
See Also:
lockWrite(), unlock()

lockWrite

public void lockWrite()
Obtain a write lock, blocks until exclusive access can be granted.
Throws:
IllegalStateException - if an attempt is made to upgrade a read lock to a write lock.
See Also:
lockRead(), unlock()

unlock

public void unlock()
Decreases the nest count, if zero the lock is released.
Throws:
IllegalStateException - if no lock is held.
See Also:
lockRead(), lockWrite()