Wird mein Thread tatsächlich blockiert, wenn ich wait() in einer synchronisierten Methode wie dieser verwende?
Code: Select all
class Product{
Product(){
q = 0;
}
synchronized void add(){
try{
notify();
System.out.println("1");
wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("Zavrseno "+Thread.currentThread().getName());
notifyAll();
}
synchronized void reduce(){
try{
notify();
System.out.println("2");
wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
notifyAll();
System.out.println("Finished "+Thread.currentThread().getName());
}
int q;
}
Mobile version