de.schlichtherle.io
Class ReentrantReadWriteLock
java.lang.Object
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:
- This class requires J2SE 1.4 only.
- This class performs better than its overengineered colleague in JSE 1.5.
- This class provides locks which provide a different set of methods
(with the same functionality in the common subset) in order to suit
the particular needs of TrueZIP (see
ReentrantLock).
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
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
ReentrantReadWriteLock
ReentrantReadWriteLock()
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()
Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.