info.aduna.concurrent.locks
Class ReadPrefReadWriteLockManager

java.lang.Object
  extended by info.aduna.concurrent.locks.AbstractReadWriteLockManager
      extended by info.aduna.concurrent.locks.ReadPrefReadWriteLockManager
All Implemented Interfaces:
ReadWriteLockManager

public class ReadPrefReadWriteLockManager
extends AbstractReadWriteLockManager

A read/write lock manager with reader preference. This lock manager block any requests for write locks until all read locks have been released.

Author:
Arjohn Kampman

Nested Class Summary
 
Nested classes/interfaces inherited from class info.aduna.concurrent.locks.AbstractReadWriteLockManager
AbstractReadWriteLockManager.ReadDebugLock, AbstractReadWriteLockManager.ReadLock, AbstractReadWriteLockManager.WriteDebugLock, AbstractReadWriteLockManager.WriteLock
 
Field Summary
 
Fields inherited from class info.aduna.concurrent.locks.AbstractReadWriteLockManager
activeReaders, writerActive
 
Constructor Summary
ReadPrefReadWriteLockManager()
          Creates a MultiReadSingleWriteLockManager.
ReadPrefReadWriteLockManager(boolean trackLocks)
          Creates a new MultiReadSingleWriteLockManager, optionally with lock tracking enabled.
 
Method Summary
 Lock getReadLock()
          Gets a read lock.
 Lock getWriteLock()
          Gets an exclusive write lock.
 Lock tryReadLock()
          Gets a read lock, if available.
 Lock tryWriteLock()
          Gets an exclusive write lock, if available.
 
Methods inherited from class info.aduna.concurrent.locks.AbstractReadWriteLockManager
createReadLock, createWriteLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadPrefReadWriteLockManager

public ReadPrefReadWriteLockManager()
Creates a MultiReadSingleWriteLockManager.


ReadPrefReadWriteLockManager

public ReadPrefReadWriteLockManager(boolean trackLocks)
Creates a new MultiReadSingleWriteLockManager, optionally with lock tracking enabled.

Parameters:
trackLocks - Controls whether the lock manager will keep track of active locks. Enabling lock tracking will add some overhead, but can be very useful for debugging.
Method Detail

tryReadLock

public Lock tryReadLock()
Gets a read lock, if available. This method will return null if the read lock is not immediately available.


getReadLock

public Lock getReadLock()
                 throws java.lang.InterruptedException
Gets a read lock. This method blocks when a write lock is in use or has been requested until the write lock is released.

Throws:
java.lang.InterruptedException - In case the thread requesting the lock was interrupted.

tryWriteLock

public Lock tryWriteLock()
Gets an exclusive write lock, if available. This method will return null if the write lock is not immediately available.


getWriteLock

public Lock getWriteLock()
                  throws java.lang.InterruptedException
Gets an exclusive write lock. This method blocks when the write lock is in use or has already been requested until the write lock is released. This method also block when read locks are active until all of them are released.

Throws:
java.lang.InterruptedException - In case the thread requesting the lock was interrupted.


Copyright © 2010 Aduna. All Rights Reserved.