public
class
PutTakeConnector
{
    boolean putting_ = false;
    Object item_ = null;

    public
    synchronized
    void
    put(Object e)
    {
	if ( e == null)
	    return;
	
	while(putting_)
	    try { wait(); } catch (InterruptedException ex) {}
	
	putting_ = true;

	item_ = e;

	notifyAll();

	while(item_ != null)
	    try { wait(); } catch (InterruptedException ex) {}

	putting_ = false;

	notifyAll();

    }

    public
    synchronized
    Object
    take()
    {

	while(item_ == null)
	    try { wait(); } catch (InterruptedException ex) {}

	Object e = item_;

	item_ = null;

	notifyAll();

	return e;
    }
}



Last Updated