Page 1 of 1

About Question enthuware.ocpjp.v7.2.1470 :

Posted: Thu Aug 04, 2016 1:43 am
by pfilaretov
Hi!
I think there are two correct answers: one described in explanation and another with opposite values of the flag in methods produce() and consume(). Here is the latter:

Code: Select all

public class ProdCon {
	private boolean flag = false;
	
	public synchronized void produce() {
		flag = false;
		notifyAll();
	}
	
	public synchronized void consume() {
		while (flag) {
			try {
				wait();
			} catch(Exception e) { e.printStackTrace(); }
		}
		flag = true;
	}
}

Re: About Question enthuware.ocpjp.v7.2.1470 :

Posted: Thu Aug 04, 2016 10:29 pm
by admin
You are right. This is correct as well.
thank you for your feedback!
Paul.