FileDocCategorySizeDatePackage
NamedConsumer.javaAPI DocExample848Sat Apr 23 22:35:36 BST 2005None

NamedConsumer

public class NamedConsumer extends Object implements Runnable

Fields Summary
Producer
producer
String
name
Constructors Summary
NamedConsumer(String name, Producer producer)

        this.producer = producer;
        this.name = name;
    
Methods Summary
public static voidmain(java.lang.String[] args)

        Producer producer = new Producer();
        new Thread( producer ).start();

        NamedConsumer consumer = new NamedConsumer( "One", producer );
        new Thread( consumer ).start();
        consumer = new NamedConsumer( "Two", producer );
        new Thread( consumer ).start();
    
public voidrun()

        while ( true ) {
            String message = producer.getMessage();
            System.out.println(name + " got message: " + message);
			try { 
				Thread.sleep( 2000 ); 
			} catch ( InterruptedException e ) { }
        }