class Canteen {
private int n_chickens = 0;
public synchronized int get(int id) {
while (n_chickens == 0) {
wait(); // Wot, No Chickens!
}
n_chickens--;// Those look good...one please
return 1;
}
public synchronized void put(int value) {
Thread.sleep(3000); // delivering chickens..
n_chickens += value;
notifyAll (); // Chickens ready!
} }
Previous slide | Next slide | Back to first slide | View graphic version |