public class Cashier implements Runnable { private CustomerLine line; private static boolean allDoneYet; public Cashier(CustomerLine line) { this.line = line; allDoneYet = false; } public void run() { while (!allDoneYet) { if (!line.isEmpty()) { Customer c = line.dequeue(); c.process(); if (allDoneYet = c.isLast()) notifyAll(); } else Thread.wait(); } } }