Ma perchè in questo codice preso dal libro si effettua la wait direttamente sul run() qual'è la differenza? grazie
codice:class MioThread extends Thread { private int num; private int succ; private MioThread[] ref; private boolean stato; //true: attivo false: disattivo public MioThread(int num, int succ) { this.num = num; this.succ = succ; this.stato = (num == 0); } public void setArray(MioThread[] ar) { ref = ar; } public synchronized void attiva() { stato = true; notify(); // CON QUESTO FUNZIONA } public synchronized void run() { try{ while(!stato) wait(); Console.scriviStringa("MioThread "+num); }catch(InterruptedException e){ } if(succ!=-1) { ref[succ].attiva(); } } }

Rispondi quotando