org.metasyntactic.thread
Class WritersPreferredMonitor

java.lang.Object
  |
  +--org.metasyntactic.thread.WritersPreferredMonitor
All Implemented Interfaces:
ReaderWriterMonitor

public class WritersPreferredMonitor
extends java.lang.Object
implements ReaderWriterMonitor

Implementation of MultipleReadersWritersMonitor that gives preference to writers. A reader may not begin reading if there is a writer writing or waiting to write; otherwise, it may begin immediately. A writer may not begin writing if there are any readers reading or if another writer is writing.

See Also:
ReaderWriterMonitor

Field Summary
protected  int readersReading
          Number readers reading
protected  int readersTotal
          Number of readers total (reading or waiting to read)
protected  int writersTotal
          Number of writers total (writing or waiting to write)
protected  int writerWriting
          Number writers writing, false or true
 
Constructor Summary
WritersPreferredMonitor()
           
 
Method Summary
 void startReading()
          Called to begin reading the shared data structure.
 void startWriting()
          Called to begin writing the shared data structure.
 void stopReading()
          Called when the thread is finished reading the shared data structure.
 void stopWriting()
          Called when the thread is finished writing the shared data structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

readersReading

protected int readersReading
Number readers reading


readersTotal

protected int readersTotal
Number of readers total (reading or waiting to read)


writerWriting

protected int writerWriting
Number writers writing, false or true


writersTotal

protected int writersTotal
Number of writers total (writing or waiting to write)

Constructor Detail

WritersPreferredMonitor

public WritersPreferredMonitor()
Method Detail

startReading

public void startReading()
                  throws java.lang.InterruptedException
Description copied from interface: ReaderWriterMonitor
Called to begin reading the shared data structure. exception InterruptedException If interrupted while waiting for access.

Specified by:
startReading in interface ReaderWriterMonitor
Throws:
java.lang.InterruptedException - When the thread is interrupted before starting

stopReading

public void stopReading()
Description copied from interface: ReaderWriterMonitor
Called when the thread is finished reading the shared data structure.

Specified by:
stopReading in interface ReaderWriterMonitor

startWriting

public void startWriting()
                  throws java.lang.InterruptedException
Description copied from interface: ReaderWriterMonitor
Called to begin writing the shared data structure. exception InterruptedException If interrupted while waiting for access.

Specified by:
startWriting in interface ReaderWriterMonitor
Throws:
java.lang.InterruptedException - When the thread is interrupted before starting

stopWriting

public void stopWriting()
Description copied from interface: ReaderWriterMonitor
Called when the thread is finished writing the shared data structure.

Specified by:
stopWriting in interface ReaderWriterMonitor