Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Problème avec NotifyAll et Thread

Aucune réponse
Avatar
florianter
Bonjour,
Je n'arrive pas à trouver pourquoi, ma méthode wake(), ne réveille pas la méthode wait(). Le réveille s'effectue seulement au bout du délai fixé dans wait(delai). Quelqu'un aurait il une solution svp?


public class ThreadPartie extends Thread {
Partie p;
long delai;

public ThreadPartie(Partie p, long delai) {
this.p = p;
this.delai = delai;
}

public synchronized void wake(){

this.notify();

}

public synchronized void run() {
try {
// pause

wait(delai);

} catch (InterruptedException ex) {
}
System.out.println("fin");
}
}
}

public class Principale {

public static void main(String[] args) {

Dictionnaire d = new Dictionnaire("dictionnaire");
Partie p = new Partie(d,0,200000,1);

ThreadPartie t = new ThreadPartie(p,10000);
t.start();
t.wake();

}

}

Réponses