Extension SDK 10.1.2

oracle.javatools.buffer
Class ReadWriteLock

java.lang.Object
  extended byoracle.javatools.buffer.ReadWriteLock

public final class ReadWriteLock
extends java.lang.Object

The ReadWriteLock class is a basic implementation of a read/write or shared/exclusive lock. It takes care of reference counting to make sure that every readLock() and writeLock() is balanced by the corresponding readUnlock() and writeUnlock() call.

Overlapping of readLock() and readUnlock() pairs with writeLock() and writeLock() pairs with the same thread are allowed. A thread that has acquired a readLock() and is requesting a writeLock() must still wait until all other readers have let go of their lock to proceed. Nested readLock() and readUnlock() pairs are always allowed.

This implementation does not provide a guarantee to prevent writers from being starved.

Although this class is declared public, it is part of the implementation, and not part of the published API.


Field Summary
static int EXCLUSIVE
          Constant which indicates that the lock is held in write mode.
static int FREE
          Constant which indicates that the lock is free.
static int NONE
          Constant which indicates that the lock is free.
static int READ
          Constant which indicates that the lock is held in read mode.
static int SHARED
          Constant which indicates that the lock is held in read mode.
static int WRITE
          Constant which indicates that the lock is held in write mode.
 
Constructor Summary
ReadWriteLock()
          Constructs a new ReadWriteLock - the lock is created initially in the unowned state.
 
Method Summary
 void assertLockHeld()
          Routine useful for making sure the current thread holds one of the locks.
 void assertLockNotHeld()
          Routine useful for making sure the current thread holds one of the locks.
 void assertReadLockHeld()
          Routine useful for making sure that the current thread does in fact holds the read lock specifically
 void assertWriteLockHeld()
          Routine useful for making sure that the current thread does in fact hold the write lock.
 void readLock()
          Blocking attempt to acquire a read or shared lock.
 void readUnlock()
          Releases a previously acquired read lock.
 void writeLock()
          Blocking attempt to acquire a write or exclusive lock.
 void writeUnlock()
          Releases a previously acquired write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Constant which indicates that the lock is free. Same as FREE.

See Also:
Constant Field Values

FREE

public static final int FREE
Constant which indicates that the lock is free. Same as NONE.

See Also:
Constant Field Values

READ

public static final int READ
Constant which indicates that the lock is held in read mode. Same as SHARED.

See Also:
Constant Field Values

SHARED

public static final int SHARED
Constant which indicates that the lock is held in read mode. Same as READ.

See Also:
Constant Field Values

WRITE

public static final int WRITE
Constant which indicates that the lock is held in write mode. Same as EXCLUSIVE.

See Also:
Constant Field Values

EXCLUSIVE

public static final int EXCLUSIVE
Constant which indicates that the lock is held in write mode. Same as WRITE.

See Also:
Constant Field Values
Constructor Detail

ReadWriteLock

public ReadWriteLock()
Constructs a new ReadWriteLock - the lock is created initially in the unowned state.

Method Detail

readLock

public void readLock()
Blocking attempt to acquire a read or shared lock.


readUnlock

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


writeLock

public void writeLock()
Blocking attempt to acquire a write or exclusive lock.


writeUnlock

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


assertLockNotHeld

public void assertLockNotHeld()
Routine useful for making sure the current thread holds one of the locks.


assertLockHeld

public void assertLockHeld()
Routine useful for making sure the current thread holds one of the locks.


assertReadLockHeld

public void assertReadLockHeld()
Routine useful for making sure that the current thread does in fact holds the read lock specifically


assertWriteLockHeld

public void assertWriteLockHeld()
Routine useful for making sure that the current thread does in fact hold the write lock.


Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.