Mam problem s nasledujicim kodem:
public class CekaciTrida extends Thread {
@Override
synchronized public void run() {
System.out.println("ceka");
try {
wait();
} catch (InterruptedException ex) {
Logger.getLogger(CekaciTrida.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("probuzek - konci");
}//edn of method
}
//---------------------------------------------------------------------------------------------------------
public class ProbouzeciTrida extends Thread {
@Override
synchronized public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(ProbouzeciTrida.class.getName()).log(Level.SEVERE, null, ex);
}
notify();
System.out.println("probudil jsem ho");
}
}
//------------------------------------------------------------------------------------------------------------------------------------
synchronized public static void main(String[] args) {
// TODO code application logic here
CekaciTrida cekaci = new CekaciTrida();
ProbouzeciTrida probouzeci = new ProbouzeciTrida();
cekaci.start();
System.out.println("kurde");
probouzeci.start();
}
Proc se mi prvni vlakno neprobudi z wait, ikdyz volam notifyall? Diky.