Exemple #1
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       print(carQueue.take());
     }
   } catch (InterruptedException e) {
     print("Exiting Reporter via interrupt");
   }
   print("Reporter off");
 }
Exemple #2
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // Blocks until chassis is available:
       car = chassisQueue.take();
       // Hire robots to perform work:
       robotPool.hire(EngineRobot.class, this);
       robotPool.hire(DriveTrainRobot.class, this);
       robotPool.hire(WheelRobot.class, this);
       barrier.await(); // Until the robots finish
       // Put car into finishingQueue for further work
       finishingQueue.put(car);
     }
   } catch (InterruptedException e) {
     print("Exiting Assembler via interrupt");
   } catch (BrokenBarrierException e) {
     // This one we want to know about
     throw new RuntimeException(e);
   }
   print("Assembler off");
 }
Exemple #3
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       TimeUnit.MILLISECONDS.sleep(500);
       // Make chassis:
       Car c = new Car(counter++);
       print("ChassisBuilder created " + c);
       // Insert into queue
       carQueue.put(c);
     }
   } catch (InterruptedException e) {
     print("Interrupted: ChassisBuilder");
   }
   print("ChassisBuilder off");
 }