Bonsoir,
j'ai essayé d'écrire un programme qui utilisé wait et notify, il se compile mais lorsque je l'execute, il ne m'affiche rien, d'ou vient l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
39
40
41
42
43
 
public class Main {
 
	public static void main(String[] args) {
 
 
		final Calcul t = new Calcul();
 
		Thread t2 = new Thread() {
			public void run() {
				synchronized(t) {
					try { t.wait(); } catch(InterruptedException e) {out.printf("nari nari nari");}
					System.out.println(t.getSomme());
				}
			}
		};
 
		t.start();
		try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
		t2.start();
 
	}
 
}
 
class Calcul extends Thread {
 
	public void run() {
		synchronized(this) {
			for(int i = 0;i<100;i++) {
				somme+=i;
			}
			this.notifyAll();
		}
	}
 
	private int somme;
 
	public int getSomme() {
		return somme;
	}
 
};
Merci d'avance pour votre aide