[Thread] Probleme sur wait() / notify()
Bonjour,
Je vous expose mon probleme :
voici 2 classes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class UnThread extends Thread {
public void run() {
synchronized (this) {
int i = 0;
while (i < 5) {
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(i);
}
}
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class TestWait {
public static void main(String[] args) {
UnThread u = new UnThread();
u.start();
synchronized (u) {
try {
u.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("Si je vois ca j'ai rien compris!");
}
} |
et quand je lance la classe TestWait forcément j'ai ca :(
Code:
1 2 3 4 5 6
| 1
2
3
4
5
Si je vois ca j'ai rien compris! |
Je m'attendais a etre bloqué sur le wait() car je n'ai pas mis de notify() dans ma classe UnThread, ou est ce que mon raisonnement est faux SVP ?
merci ;)