ER-087 Do not use 'notify ()'; use 'notifyAll ()' instead

Severity3
Enabledyes
Waivable
Violation
public synchronized int get() {
	while (available) {
		try {
			// wait for Producer to put value
			wait();
		} catch (InterruptedException e) {
			logger.warn(e);
		}
	}
	available = false;
	// notify Producer that value has been retrieved
	notify();
	return contents;
}
public synchronized void put(final int value) {
	while (available) {
		try {
			// wait for Consumer to get value
			wait();
		} catch (InterruptedException e) {
			logger.warn(e);
		}
	}
	contents = value;
	available = true;
	// notify Consumer that value has been set
	notify();
} 
Fix
public synchronized int get() {
	while (available) {
		try {
			// wait for Producer to put value
			wait();
		} catch (InterruptedException e) {
			logger.warn(e);
		}
	}
	available = false;
	// notify Producer that value has been retrieved
	notifyAll();
	return contents;
}
public synchronized void put(final int value) {
	while (available) {
		try {
			// wait for Consumer to get value
			wait();
		} catch (InterruptedException e) {
			logger.warn(e);
		}
	}
	contents = value;
	available = true;
	// notify Consumer that value has been set
	notifyAll();
} 


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.