I was thinking about this code:
public class SharedVariable<T> {
private T value;
public SharedVariable(T init){
this.value = init;
}
public synchronized void testAndSet(Predicate<? super T> p, T value)
throws InterruptedException{
while (!p.test(this.value)){
this.wait();
this.value = value;
}
this.notifyAll();
}
}
Would it be possible to replace .notifyAll()
with .notify();
? Could problems arise?