FileDocCategorySizeDatePackage
Producer.javaAPI DocExample846Sat Apr 23 22:35:36 BST 2005None

Producer

public class Producer extends Object implements Runnable

Fields Summary
static final int
MAXQUEUE
private List
messages
Constructors Summary
Methods Summary
public synchronized java.lang.StringgetMessage()

        while ( messages.size() == 0 )
			try {
				notify();
				wait();
			} catch( InterruptedException e ) { }
        String message = (String)messages.remove(0);
		notify();
        return message;
    
private synchronized voidputMessage()

        while ( messages.size() >= MAXQUEUE )
			try {
				wait();
			} catch( InterruptedException e ) { }

        messages.add( new java.util.Date().toString() );
        notify();
    
public voidrun()


       
		while ( true ) {
			putMessage();
            try { 
				Thread.sleep( 1000 ); 
			} catch ( InterruptedException e ) { }
		}