public synchronized void waitForBuffingO throws InterruptedException {
while(waxOn == true)
waitO;
}
}
class WaxOn implements Runnable { private Car car;
public WaxOn(Car c) { car = c; } public void run() { try {
while( IThread interruptedO) { printnbC'Wax On! "); Ti mellni t. MILLISECONDS. si eep( 200); car.waxedO; car.waitForBuffingO;
}
} catchdnterruptedException e) {
printC'Exiting via interrupt");
}
print("Ending Wax On task");
}
}
class WaxOff implements Runnable { private Car car;
public WaxOff(Car c) { car = c; } public void runO { try {
while(IThread.interruptedO) { car.waitForWaxingO; printnbC'Wax Off! "); Ti mellni t. MILLI SECONDS. s 1 eep (200); car.buffedO;
}
} catchdnterruptedException e) {
printC'Exiting via interrupt");
}
printC'Ending Wax Off task");
public class WaxOMatic {
public static void main(String[] args) throws Exception { Car car = new CarO;
ExecutorService exec = Executors.newCachedThreadPoolО;
exec.execute(new WaxOff(car));
exec.execute(new WaxOn(car));
TimeUnit SECONDS.sieep(5); // Небольшая задержка. .