About Question enthuware.ocpjp.v7.2.1470 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

About Question enthuware.ocpjp.v7.2.1470 :

Post 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;
	}
}

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You are right. This is correct as well.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests