コード例 #1
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // A new customer arrives; assign a WaitPerson:
       WaitPerson wp = waitPersons.get(rand.nextInt(waitPersons.size()));
       Customer c = new Customer(wp);
       exec.execute(c);
       TimeUnit.MILLISECONDS.sleep(100);
     }
   } catch (InterruptedException e) {
     print("Restaurant interrupted");
   }
   print("Restaurant closing");
 }
コード例 #2
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // Blocks until an order appears:
       Order order = restaurant.orders.take();
       Food requestedItem = order.item();
       // Time to prepare order:
       TimeUnit.MILLISECONDS.sleep(rand.nextInt(500));
       Plate plate = new Plate(order, requestedItem);
       order.getWaitPerson().filledOrders.put(plate);
     }
   } catch (InterruptedException e) {
     print(this + " interrupted");
   }
   print(this + " off duty");
 }