Package org.jfree.threads
Class ReaderWriterLock
- java.lang.Object
-
- org.jfree.threads.ReaderWriterLock
-
public class ReaderWriterLock extends java.lang.ObjectA reader-writer lock from "Java Threads" by Scott Oak and Henry Wong.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReaderWriterLock.ReaderWriterNodeA node for the waiting list.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayListwaitersThe waiting threads.
-
Constructor Summary
Constructors Constructor Description ReaderWriterLock()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intfirstWriter()Returns the index of the first waiting writer.private intgetIndex(java.lang.Thread t)Returns the index of a thread.voidlockRead()Grab the read lock.voidlockWrite()Grab the write lock.voidunlock()Unlock.
-
-
-
Method Detail
-
lockRead
public void lockRead()
Grab the read lock.
-
lockWrite
public void lockWrite()
Grab the write lock.
-
unlock
public void unlock()
Unlock.
-
firstWriter
private int firstWriter()
Returns the index of the first waiting writer.- Returns:
- The index.
-
getIndex
private int getIndex(java.lang.Thread t)
Returns the index of a thread.- Parameters:
t- the thread.- Returns:
- The index.
-
-