threadExamples
Class SingleMessageBox<V>

java.lang.Object
  extended by threadExamples.SingleMessageBox<V>
Type Parameters:
V - The type of "message" that may be put into this SingleMessageBox.

public class SingleMessageBox<V>
extends java.lang.Object

Implements a message box which can hold only a single message at a time. Behavior is almost identical to that of BatonMessageBox, but the implementation is different: the put and get methods are themselves synchronized, rather than using a separate object on which to synchronize.

Version:
January 28, 2008
Author:
David Matuszek

Constructor Summary
SingleMessageBox()
          Creates an empty SingleMessageBox.
 
Method Summary
 V get()
          Waits until there is a "message" of type V in this SingleMessageBox, then removes and returns it.
 void put(V nextValue)
          Waits until this SingleMessageBox is empty, then puts the given "message" of type V into it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleMessageBox

public SingleMessageBox()
Creates an empty SingleMessageBox.

Method Detail

put

public void put(V nextValue)
Waits until this SingleMessageBox is empty, then puts the given "message" of type V into it.

Parameters:
nextValue - The message to be added. Should not be null.

get

public V get()
Waits until there is a "message" of type V in this SingleMessageBox, then removes and returns it.

Returns:
The message removed from this Queue.