public void run() { try { while (!Thread.interrupted()) { // Blocks until next piece of toast is available: Toast t = dryQueue.take(); t.butter(); print(t); butteredQueue.put(t); } } catch (InterruptedException e) { print("Butterer interrupted"); } print("Butterer off"); }
public void run() { try { while (!Thread.interrupted()) { TimeUnit.MILLISECONDS.sleep(100 + rand.nextInt(500)); // Make toast Toast t = new Toast(count++); print(t); // Insert into queue toastQueue.put(t); } } catch (InterruptedException e) { print("Toaster interrupted"); } print("Toaster off"); }