import java.util.Random; class Message { private String payload; private boolean empty = true; public synchronized String read() { while(empty) { try { wait(); } catch(InterruptedException e) { } } empty = true; notifyAll(); return payload; } public synchronized void write(String payload) { while(!empty) { try { wait(); } catch(InterruptedException e) { } } empty = false; this.payload = payload; notifyAll(); } } class Writer implements Runnable { private Message message; public Writer(Message message) { this.message = message; } public void run() { String payload[] = { "Humpty Dumpty sat on a wall", "Humpty Dumpty had a great fall", "All the king's horses and all the king's men", "Couldn't put Humpty together again" }; Random random = new Random(); for(int i=0; i