TrueZIP 6.8.3

de.schlichtherle.io
Class ReentrantReadWriteLock

java.lang.Object
  extended by de.schlichtherle.io.ReentrantReadWriteLock
All Implemented Interfaces:
ReadWriteLock

final class ReentrantReadWriteLock
extends Object
implements ReadWriteLock

Similar to java.util.concurrent.locks.ReentrantReadWriteLock with the following differences:

Note: In accordance with JSE 1.5, upgrading a read lock to a write lock is not possible. Any attempt to do so will lock the current thread. This is a constraint which can't be fixed properly: If this constraint would not exist, two reader threads could try to upgrade from a read lock to a write lock concurrently, effectively dead locking them. By locking this thread immediately on any attempt to do so, this is considered to be a programming error which can be easily fixed without affecting any other thread.

On the other hand, it is possible to downgrade from a write lock to a read lock. Please consult the JSE 1.5 Javadoc of the class java.util.concurrent.locks.ReentrantReadWriteLock for more information.

Since:
TrueZIP 6.2
Author:
Christian Schlichtherle

Nested Class Summary
private static class ReentrantReadWriteLock.AbstractLock
           
private  class ReentrantReadWriteLock.ReadLock
           
private  class ReentrantReadWriteLock.WriteLock
           
 
Field Summary
private static String CLASS_NAME
           
private static Logger logger
           
private  ReentrantReadWriteLock.ReadLock readLock
           
private  int totalReadLockCount
           
private  int totalWriteLockCount
           
private  ReentrantReadWriteLock.WriteLock writeLock
           
 
Constructor Summary
ReentrantReadWriteLock()
           
 
Method Summary
private  void lockRead()
           
private  void lockReadInterruptibly()
           
private  void lockWrite()
           
private  void lockWriteInterruptibly()
           
 ReentrantLock readLock()
          Returns the lock for reading.
private  boolean tryLockRead()
           
private  boolean tryLockWrite()
           
private  void unlockRead()
           
private  void unlockWrite()
           
 ReentrantLock writeLock()
          Returns the lock for writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

logger

private static final Logger logger

readLock

private final ReentrantReadWriteLock.ReadLock readLock

writeLock

private final ReentrantReadWriteLock.WriteLock writeLock

totalWriteLockCount

private int totalWriteLockCount

totalReadLockCount

private int totalReadLockCount
Constructor Detail

ReentrantReadWriteLock

ReentrantReadWriteLock()
Method Detail

readLock

public ReentrantLock readLock()
Returns the lock for reading. Like its cousin in JSE 1.5, the returned lock does not support upgrading to a write lock.

Specified by:
readLock in interface ReadWriteLock

writeLock

public ReentrantLock writeLock()
Returns the lock for writing. Like its cousin in JSE 1.5, the returned lock does support downgrading to a read lock.

Specified by:
writeLock in interface ReadWriteLock

lockRead

private void lockRead()

lockReadInterruptibly

private void lockReadInterruptibly()
                            throws InterruptedException
Throws:
InterruptedException

tryLockRead

private boolean tryLockRead()

unlockRead

private void unlockRead()

lockWrite

private void lockWrite()

lockWriteInterruptibly

private void lockWriteInterruptibly()
                             throws InterruptedException
Throws:
InterruptedException

tryLockWrite

private boolean tryLockWrite()

unlockWrite

private void unlockWrite()

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.