Предположим, у меня есть 2 темы.
Каждый поток выполняется 100 раз.
В чем разница между использованием notify () или notifyAll () в методе увеличения (...)?
class Monitor1 {
private volatile int compar;
public Monitor1(int val) {
compar = val;
}
synchronized public void decrease(int amount) {
while (amount > compar) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
compar -= amount;
System.out.println("variable=" + compar);
}
synchronized public void increase(int amount) {
compar += amount;
notifyAll();
System.out.println("variable=" + compar);
}
}
Я проверяю вывод, который я получаю, используя notify () или notifyAll (), но не могу прийти к какому-либо заключению.