org.apache.java.lang
Class Lock

java.lang.Object
  |
  +--org.apache.java.lang.Lock

public class Lock
extends java.lang.Object

This is a reader/writer lock object. The code is vaugely based on an example from _Concurrent Programming in Java_, by Doug Lea.

As implemented, JServLock works as an actual "lock" object, which another object will set up and lock and unlock. It blocks incoming readers if there are waiting writers.

There are method that wait only at specified amount of time before failing with TimeoutException.


Constructor Summary
Lock()
           
 
Method Summary
 void readLock()
          Wait for a read lock.
 void readLock(long timeout)
          Wait for a read lock.
 void readUnlock()
          Unlocks a previously acquired read lock.
 void writeLock()
          Wait for a read lock.
 void writeLock(long timeout)
          Wait for a read lock.
 void writeUnlock()
          Unlock a previously acquired write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lock

public Lock()
Method Detail

readLock

public void readLock()
              throws java.lang.InterruptedException
Wait for a read lock. This will wait for all write lock to be removed before returning.
Throws:
java.lang.InterruptedException - if the wait is interrupted. Calling thread must consider the operation to have failed and stop its processing.

readLock

public void readLock(long timeout)
              throws java.lang.InterruptedException,
                     TimeoutException
Wait for a read lock. This will wait for all write lock to be removed before returning.
Parameters:
timeout - the number of millisecond before giving up and failing with a TimeoutException.
Throws:
TimeoutException - if the lock isn't acquired after the specified amount of time.
java.lang.InterruptedException - if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.

readUnlock

public void readUnlock()
Unlocks a previously acquired read lock.

writeLock

public void writeLock()
               throws java.lang.InterruptedException
Wait for a read lock. This will wait until all read lock have been removed and no other write lock are active.
Throws:
java.lang.InterruptedException - if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.

writeLock

public void writeLock(long timeout)
               throws java.lang.InterruptedException,
                      TimeoutException
Wait for a read lock. This will wait until all read lock have been removed and no other write lock are active.
Parameters:
timeout - the number of millisecond before giving up and failing with a TimeoutException.
Throws:
TimeoutException - if the lock isn't acquired after the specified amount of time.
java.lang.InterruptedException - if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.

writeUnlock

public void writeUnlock()
Unlock a previously acquired write lock.