org.wamblee.concurrency
Class ReadWriteLock

java.lang.Object
  extended by org.wamblee.concurrency.ReadWriteLock

public class ReadWriteLock
extends java.lang.Object

Read-write lock for allowing multiple concurrent readers or at most one writer. This implementation does not aim for high performance but for robustness and simplicity. Users of this class should not synchronize on objects of this class.


Constructor Summary
ReadWriteLock()
          Constructs read-write lock.
 
Method Summary
 void acquireRead()
          Acquires the lock for reading.
 void acquireWrite()
          Acquires the lock for writing.
 void releaseRead()
          Releases the lock for reading.
 void releaseWrite()
          Releases the lock for writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadWriteLock

public ReadWriteLock()
Constructs read-write lock.

Method Detail

acquireRead

public void acquireRead()
Acquires the lock for reading. This call will block until the lock can be acquired.

Throws:
java.lang.IllegalStateException - Thrown if the read or write lock is already acquired.

releaseRead

public void releaseRead()
Releases the lock for reading. Note: This implementation assumes that the lock has already been acquired for reading previously.

Throws:
java.lang.IllegalStateException - Thrown when the lock was not acquired by this thread.

acquireWrite

public void acquireWrite()
Acquires the lock for writing. This call will block until the lock has been acquired.

Throws:
java.lang.IllegalStateException - Thrown if the read or write lock is already acquired.

releaseWrite

public void releaseWrite()
Releases the lock for writing.

Throws:
java.lang.IllegalStateException - Thrown when the lock was not acquired.


Copyright © 2010. All Rights Reserved.