/* * ErrorMailbox.java * * 1.0 * * 000908 * * Leif Lindbäck. * */ public class ErrorMailbox { private int mail; /** * Sends the mail. */ public void setMail(int m) { mail = m; } /** * Returns the mail. */ public int getMail() { return mail; } /** * Tests the mailbox. */ public static void main( String[] args ) { ErrorMailbox mb = new ErrorMailbox(); new Thread( new Producer( mb ) ).start(); new Thread( new Consumer( mb ) ).start(); } } /** * A thread that puts mail in the mailbox. */ class Producer implements Runnable { private ErrorMailbox mb; /** * Constructs a Runnable that puts mail in the specified mailbox. */ public Producer( ErrorMailbox mb ) { this.mb = mb; } /** * Prints messages and puts them in the mailbox. */ public void run() { int mailNo = 0; for (;;) { System.out.println( "<<>>>>taking mail no " + mb.getMail() ); } } }