Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

Name

ReentrantReadWriteLock

Synopsis

This class implements the ReadWriteLock interface. The locks returned by the readLock( ) and writeLock( ) methods are instances of the inner classes ReadLock and WriteLock. ReentrantReadWriteLock defines a “fair mode” and includes instrumentation methods like ReentrantLock does.

Any number of threads can acquire the read lock as long as no thread holds or is attempting to acquire the write lock. When a thread attempts to acquire the write lock, no new read locks are granted. When all existing readers have relinquished the lock, the writer acquires the lock, and no reads are allowed until the writer has relinquished it. A thread that holds the write lock may downgrade to a read lock by acquiring the read lock and then relinquishing the write lock.

Because the read lock is not exclusive, it cannot have a Condition associated with it. The ReadLock.newCondition( ) method throws UnsupportedOperationException.

java.util.concurrent.locks.ReentrantReadWriteLock

Figure 16-106. java.util.concurrent.locks.ReentrantReadWriteLock

public class ReentrantReadWriteLock implements ReadWriteLock, Serializable {
// Public Constructors
     public ReentrantReadWriteLock( );  
     public ReentrantReadWriteLock(boolean fair);  
// Nested Types
     public static class ReadLock implements Lock, Serializable; 
     public static class WriteLock implements Lock, Serializable; 
// Public Instance Methods
     public final int getQueueLength( );                                  default:0 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page