public void run() { try { while (!Thread.interrupted()) { Customer customer = customers.take(); TimeUnit.MILLISECONDS.sleep(customer.getServiceTime()); synchronized (this) { customersServed++; while (!servingCustomerLine) wait(); } } } catch (InterruptedException e) { System.out.println(this + "interrupted"); } System.out.println(this + "terminating"); }