Witam, mam taki kawalek kodu:
package test;
//--------------------
class Randezvous {
public synchronized youWillWait() {
try {
wait();
} catch (InterruptedException exc) {}
}
public synchronized void notifyAllWaiters() {
notifyAll();
}
}
//--------------------
class Waiter extends Thread {
private Randezvous rv;
private static int waitersCount;
private int serialNo;
public Waiter(Randezvous r) {
rv = r;
serialNo = waitersCount;
++waitersCount;
}
public void run() {
rv.youWillWait();
System.out.println("Waiter #" + serialNo + " notified!");
}
}
//--------------------
public class Main {
public static void main(String[] args) {
Randezvous rand = new Randezvous();
Waiter w0 = new Waiter(rand);
w0.start();
Waiter w1 = new Waiter(rand);
w1.start();
Waiter w2 = new Waiter(rand);
w2.start();
rand.notifyAllWaiters();
}
}
Powinien on uruchomic 3 watki, zaraz po tym one sa usypiane za pomoca wait() w obiekcie klasy Randezvous. Zaraz po utworzeniu 3 watkow i uspieniu ich, wywoluje metode notifyAll(). Powinny chyba zostac wypisane na ekran wiadomosci od poszczegolnych watkow (patrz metoda run()), natomist program nic nie wypisuje i co gorsza chyba sie wiesza. Czy ktos moze mi w tym pomoc?