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.
-
JServLock()
-
-
readLock()
- Wait for a read lock.
-
readLock(long)
- Wait for a read lock.
-
readUnlock()
- Unlocks a previously acquired read lock.
-
writeLock()
- Wait for a read lock.
-
writeLock(long)
- Wait for a read lock.
-
writeUnlock()
- Unlock a previously acquired write lock.
JServLock
public JServLock()
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.
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.
readUnlock
public synchronized void readUnlock()
- Unlocks a previously acquired read lock.
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.
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.
writeUnlock
public synchronized void writeUnlock()
- Unlock a previously acquired write lock.
All Packages Class Hierarchy This Package Previous Next Index