synchronized void enterLaneB(Car car) throws InterruptedException { while (currentWeightA + currentWeightB + car.getWeight() >= maximumWeight || Math.abs(currentWeightA - currentWeightB + car.getWeight()) >= maximumDifference) { wait(); } currentWeightB += car.getWeight(); notifyAll(); }
synchronized void exitLaneB(Car car) throws InterruptedException { while (Math.abs(currentWeightA - currentWeightB) >= maximumDifference) { wait(); } currentWeightB -= car.getWeight(); notifyAll(); }