salut à tous,
Je suis un débutant dans la programmation parallèle, je dois défendre un tp en java sur la programmation parallèle le 05/09/2011
j'ai essayé de simuler l'impression sur une imprimante doté d'un spooler mais quand j'essaie de compiler ce code il me cette erreur:
Page 1 du Premier Document
Page 1 du Deuxième Document
Debut d'impression: Page de garde
Fin d'imprression0 Pages imprimées
Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
at final_Simulimp.Imprimeur.Imprimer(Impression.java:55)
at final_Simulimp.Imprimeur.run(Impression.java:70)
at java.lang.Thread.run(Unknown Source)
je vous prie de m'aider svp!

voici le code sous eclipse hellios:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package final_Simulimp;
 
public class Impression extends Thread{
 
	public Impression(String s){
		super(s);
	}
 
	static Imprimeur Printer;
	String[]pages;
	public void run(){
		synchronized (Printer) {
			pages=new String[100];
			for(int i=0;i<pages.length;i++){
				System.out.println("Page "+(i+1)+" du "+getName());
				Printer.spool(pages);
				//Printer.Imprimer();
 
				}
 
		}
	}
	public static void main(String[] args) {
		Printer= new Imprimeur();
 
		new Impression(" Premier Document").start();
		new Impression(" Deuxième Document").start();
	}
 
}
class Materiel{}
class Imprimeur extends Materiel implements Runnable{
	String []spooler=new String[100];
	int index=0;
	boolean pageEnAttente=false, runnable=false;
	Thread ImprimanteThread;
 
	Imprimeur(){
		ImprimanteThread=new Thread(Imprimeur.this);
		ImprimanteThread.setDaemon(true);
		ImprimanteThread.start();
	}
	public void Imprimer(){
		System.out.println("Debut d'impression: Page de garde");
		int j=0;
		for(int i=0;i<spooler.length;i++){
			if (spooler[i]!=null){
				//System.out.println(spooler[i]);
				j++;
				spooler[i]=null;
				}
		}
		System.out.println("Fin d'imprression"+j+" Pages imprimées");
		pageEnAttente=false;
		notifyAll();
	}
	public synchronized void spool(String[]p){
		for(int i= 0;i<p.length;i++)
			spooler[index]=p[i];
			pageEnAttente=true;
			try{
				wait();
				}catch(InterruptedException e){}
 
	}
	public void run(){
		ImprimanteThread.setPriority(ImprimanteThread.MIN_PRIORITY);
		while(true){
			if(pageEnAttente)
				Imprimer();
		}
	}
 
}