nbObj++;\r
tampon[prem] = obj;\r
prem = (prem + 1) % taille;\r
+ //System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);\r
notify();\r
- System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);\r
}\r
\r
\r
nbObj--;\r
outObj = tampon[der];\r
der = (der + 1) % taille;\r
+ //System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);\r
notify();\r
- System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);\r
return outObj;\r
}\r
\r
\r
\r
public static void main (String[] args) {\r
- BufferCirc b = new BufferCirc(20);\r
+ final int BUFFER_SIZE = 20;\r
+ final int PROD_NUMBER = 10;\r
+ final int CONS_NUMBER = 10;\r
+ BufferCirc b = new BufferCirc(BUFFER_SIZE);\r
Producteur p = new Producteur(b);\r
Consommateur c = new Consommateur(b);\r
- Thread P1 = new Thread(p);\r
- P1.setName("P1");\r
- Thread C1 = new Thread(c);\r
- C1.setName("C1");\r
- P1.start();\r
- C1.start();\r
+ Thread[] P = new Thread[PROD_NUMBER];\r
+ Thread[] C = new Thread[CONS_NUMBER];\r
+ for (int i = 0; i < P.length; i++) {\r
+ P[i] = new Thread(p);\r
+ P[i].setName("P" + i);\r
+ P[i].start();\r
+ }\r
+ for (int i = 0; i < C.length; i++) {\r
+ C[i] = new Thread(c);\r
+ C[i].setName("C" + i);\r
+ C[i].start();\r
+ }\r
}\r
\r
}\r