J'ai 2 threads que je veux synchroniser avec wait() et notify(). Cependant, lorsque je notifie le thread qui attend ne reprend jamais. Ce sont mes morceaux de code. Dans Lib60870, je démarre les deux threads et le thread HandShake est synchronisé avec SerialReader.notify() et wait() ne fonctionnant pas en Java
public Lib60870(){ //Here I start threads
try {
myConnection=new Connection(LOCALHOST,port);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mySerialReader.start();
myHandshake.start();}
}
Classe SerialReader
public class SerialReader extends Thread {
private static boolean isPaused=true;
@Override
public void run() {
synchronized(this){
if(Lib60870.myConnection!=null){
while(true){
if(!isPaused){
byte inByte=Lib60870.myConnection.getByte();
if(inByte==0x68){
...
}
notify();
}
else if(inByte==0x10){
...
}
notify();
}
}
}
}
}
}
public void setPause(boolean pause){
isPaused=pause;
}
Classe Handshake
public class HandShake extends Thread {
public void run() {
synchronized(Lib60870.mySerialReader){
Lib60870.mySerialReader.setPause(false);
...
try {
Lib60870.mySerialReader.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Lib60870.mySerialReader.setPause(true);
...
Lib60870.mySerialReader.setPause(false);
try {
Lib60870.mySerialReader.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Merci à l'avance
Veuillez publier un [Exemple minimal, complet et vérifiable] (http://stackoverflow.com/help/MCVE). –