Example #1
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       Toast t = butteredQueue.take();
       t.jam();
       System.err.println(t);
       finishedQueue.put(t);
     }
   } catch (InterruptedException e) {
     System.out.println("Jammer interrupted!");
   }
   System.out.println("jammer off");
 }
 public void run() {
   try {
     while (!Thread.interrupted()) {
       Toast t = dryQueue.take();
       t.butter();
       System.out.println(t);
       butterQueue.put(t);
     }
   } catch (InterruptedException e) {
     System.out.println("Butterer interrupted");
   }
   System.out.println("Butterer off");
 }
 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");
 }
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // Blocks until next piece of toast is available:
       Toast t = finishedQueue.take();
       // Verify that the toast is coming in order,
       // and that all pieces are getting jammed:
       if (t.getId() != counter++ || t.getStatus() != Toast.Status.JAMMED) {
         print(">>>> Error: " + t);
         System.exit(1);
       } else print("Chomp! " + t);
     }
   } catch (InterruptedException e) {
     print("Eater interrupted");
   }
   print("Eater off");
 }