All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.apache.jserv.JServLock

java.lang.Object
   |
   +----org.apache.jserv.JServLock

public class JServLock
extends 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 Index

 o JServLock()

Method Index

 o readLock()
Wait for a read lock.
 o readLock(long)
Wait for a read lock.
 o readUnlock()
Unlocks a previously acquired read lock.
 o writeLock()
Wait for a read lock.
 o writeLock(long)
Wait for a read lock.
 o writeUnlock()
Unlock a previously acquired write lock.

Constructors

 o JServLock
 public JServLock()

Methods

 o readLock
 public synchronized void readLock() throws InterruptedException
Wait for a read lock. This will wait for all write lock to be removed before returning.

Throws: InterruptedException
if the wait is interrupted. Calling thread must consider the operation to have failed and stop its processing.
 o readLock
 public synchronized void readLock(long timeout) throws InterruptedException, JServLock. 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: JServLock. TimeoutException
if the lock isn't acquired after the specified amount of time.
Throws: InterruptedException
if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.
 o readUnlock
 public synchronized void readUnlock()
Unlocks a previously acquired read lock.

 o writeLock
 public synchronized void writeLock() throws InterruptedException
Wait for a read lock. This will wait until all read lock have been removed and no other write lock are active.

Throws: InterruptedException
if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.
 o writeLock
 public synchronized void writeLock(long timeout) throws InterruptedException, JServLock. 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: JServLock. TimeoutException
if the lock isn't acquired after the specified amount of time.
Throws: InterruptedException
if the wait is interrupted. Calling thread must consider the operation to have failed and stops its processing.
 o writeUnlock
 public synchronized void writeUnlock()
Unlock a previously acquired write lock.


All Packages  Class Hierarchy  This Package  Previous  Next  Index