org.apache.avalon.excalibur.concurrent
Class ReadWriteLock

java.lang.Object
  |
  +--org.apache.avalon.excalibur.concurrent.ReadWriteLock

public class ReadWriteLock
extends java.lang.Object

Class implementing a read/write lock. The lock has three states - unlocked, locked for reading and locked for writing. If the lock is unlocked, anyone can aquire a read or write lock. If the lock is locked for reading, anyone can aquire a read lock, but no one can aquire a write lock. If the lock is locked for writing, no one can quire any type of lock.

When the lock is released, those threads attempting to aquire a write lock will take priority over those trying to get a read lock.

Since:
4.0
Version:
CVS $Revision: 1.7 $ $Date: 2001/12/11 09:53:28 $
Author:
Leo Sutic

Constructor Summary
ReadWriteLock()
          Default constructor.
 
Method Summary
 void aquireRead()
          Attempts to aquire a read lock.
 void aquireWrite()
          Attempts to aquire a write lock.
 void release()
          Releases a lock.
 boolean tryAquireRead()
          Attempts to aquire a read lock.
 boolean tryAquireWrite()
          Attempts to aquire a write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadWriteLock

public ReadWriteLock()
Default constructor.
Method Detail

aquireRead

public void aquireRead()
                throws java.lang.InterruptedException
Attempts to aquire a read lock. If no lock could be aquired the thread will wait until it can be obtained.
Throws:
java.lang.InterruptedException - if the thread is interrupted while waiting for a lock.

aquireWrite

public void aquireWrite()
                 throws java.lang.InterruptedException
Attempts to aquire a write lock. If no lock could be aquired the thread will wait until it can be obtained.
Throws:
java.lang.InterruptedException - if the thread is interrupted while waiting for a lock.

release

public void release()
Releases a lock. This method will release both types of locks.
Throws:
java.lang.IllegalStateException - when an attempt is made to release an unlocked lock.

tryAquireRead

public boolean tryAquireRead()
Attempts to aquire a read lock. This method returns immediately.
Returns:
true iff the lock was successfully obtained.

tryAquireWrite

public boolean tryAquireWrite()
Attempts to aquire a write lock. This method returns immediately.
Returns:
true iff the lock was successfully obtained.


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.