ca.odell.glazedlists.util.concurrent

Class J2SE14ReadWriteLock.ReadLock

Enclosing Class:
J2SE14ReadWriteLock
Implemented Interfaces:
Lock, java.io.Serializable

public static class J2SE14ReadWriteLock.ReadLock
extends java.lang.Object
implements Lock, java.io.Serializable

The lock returned by method J2SE14ReadWriteLock.readLock().
See Also:
Serialized Form

Constructor Summary

ReadLock(J2SE14ReadWriteLock lock)
Constructor for use by subclasses

Method Summary

void
lock()
Acquires the read lock.
void
lockInterruptibly()
Acquires the read lock unless the current thread is interrupted.
String
toString()
Returns a string identifying this lock, as well as its lock state.
boolean
tryLock()
Acquires the read lock only if the write lock is not held by another thread at the time of invocation.
void
unlock()
Attempts to release this lock.

Constructor Details

ReadLock

protected ReadLock(J2SE14ReadWriteLock lock)
Constructor for use by subclasses
Parameters:
lock - the outer lock object

Method Details

lock

public void lock()
Acquires the read lock.

Acquires the read lock if the write lock is not held by another thread and returns immediately.

If the write lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until the read lock has been acquired.

Specified by:
lock in interface Lock

lockInterruptibly

public void lockInterruptibly()
            throws InterruptedException
Acquires the read lock unless the current thread is interrupted.

Acquires the read lock if the write lock is not held by another thread and returns immediately.

If the write lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

  • The read lock is acquired by the current thread; or
  • Some other thread interrupts the current thread.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is interrupted while acquiring the read lock,
then InterruptedException is thrown and the current thread's interrupted status is cleared.

In this implementation, as this method is an explicit interruption point, preference is given to responding to the interrupt over normal or reentrant acquisition of the lock.


toString

public String toString()
Returns a string identifying this lock, as well as its lock state. The state, in brackets, includes the String "Read locks =" followed by the number of held read locks.
Returns:
a string identifying this lock, as well as its lock state

tryLock

public boolean tryLock()
Specified by:
tryLock in interface Lock
Returns:
true if the read lock was acquired

unlock

public void unlock()
Attempts to release this lock.

If the number of readers is now zero then the lock is made available for write lock attempts.

Specified by:
unlock in interface Lock

Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2009-07-14 22:05