\r
private BufferCirc buffer;\r
\r
-\r
public Consommateur(BufferCirc b) {\r
buffer = b;\r
}\r
\r
+ public Consommateur(BufferCirc b, String name) {\r
+ buffer = b;\r
+ setThName(name);\r
+ }\r
+\r
+ public void setThName(String name) {\r
+ Thread.currentThread().setName(name);\r
+ }\r
\r
public void run() {\r
Integer val;\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[] 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] = new Thread(new Producteur(b));\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] = new Thread(new Consommateur(b));\r
C[i].setName("C" + i);\r
C[i].start();\r
}\r
buffer = b;\r
}\r
\r
+ public Producteur(BufferCirc b, String name) {\r
+ buffer = b;\r
+ setThName(name);\r
+ }\r
+\r
+ public void setThName(String name) {\r
+ Thread.currentThread().setName(name);\r
+ }\r
\r
public void run() {\r
while (true) {\r