java.lang.IllegalMonitorStateException + CountDownLatch
bonjour,
j'ai voulu voire le fonctionement du "CountDownLatch". j'ai crée le test suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
import java.util.concurrent.CountDownLatch;
public class TestLatch {
private static CountDownLatch latch = new CountDownLatch(1);
public static final class MonThread {
public void go(){
latch.countDown();
System.out.println("On est apres le latch.countDown \n");
}
}
public static void main (String[] args){
System.out.println("1 \n");
Thread tGo = new ThreadGo();
System.out.println("2 \n");
tGo.start();
System.out.println("3 \n");
try {
latch.wait(); // c'est la ligne 57
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("4 \n");
}
} |
avec "ThreadGo" :
Code:
1 2 3 4 5 6 7 8 9 10
|
public class ThreadGo extends Thread{
MonThread mt =new MonThread();
public void run(){
mt.go();
}
} |
quand je lance le test, le résultat est le suivant:
Citation:
1
2
3
On est apres le latch.countDown
Exception in thread "main" java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Unknown Source)
at JarXYZ.TestIMS.TestLatch.main(TestLatch.java:57)
Je ne sait pas pourquoi il donne cette erreur??:cry:
can you help me?