Beispiel #1
0
 private synchronized void powerDown() throws InterruptedException {
   engage = false;
   assembler = null; // Disconnect from the Assembler
   // Put ourselves back in the available pool:
   pool.release(this);
   while (engage == false) // Power down
   wait();
 }
Beispiel #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");
 }