org.metasyntactic.thread
Class TakeANumberMonitor

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

public class TakeANumberMonitor
extends java.lang.Object
implements ReaderWriterMonitor

As each reader or writer arrives, it takes the next number and threads are served in order by their number. However, all readers with consecutive numbers are served at the same time.


Field Summary
protected  int nextNumber
          Take a number
protected  int nowServing
          Number now being served
protected  int readersReading
          Number readers reading
 
Constructor Summary
TakeANumberMonitor()
           
 
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


nextNumber

protected int nextNumber
Take a number


nowServing

protected int nowServing
Number now being served

Constructor Detail

TakeANumberMonitor

public TakeANumberMonitor()
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