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.
- Version:
- $Revision: 1.4 $ $Date: 1999/04/26 00:33:55 $
Constructor Summary |
Lock()
|
Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
toString,
wait,
wait,
wait |
activeReadLocks
private int activeReadLocks
waitingReadLocks
private int waitingReadLocks
activeWriteLocks
private int activeWriteLocks
waitingWriteLocks
private int waitingWriteLocks
Lock
public Lock()
allowReadLock
private boolean allowReadLock()
allowWriteLock
private boolean allowWriteLock()
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.
|