TD1: fix thread name setting.
[TD_SR.git] / TD1 / exo3 / Producteur.java
index 47a402180d5f8c9a6fa4854bc4b3b03f76c97858..5e09d5062cf9ebb1cad47860e89dfe53aa59ec58 100644 (file)
@@ -11,24 +11,26 @@ public class Producteur implements Runnable {
                buffer = b;
        }
 
-       public Producteur(BufferCirc b, String name) {
+       public Producteur(BufferCirc b, Thread th, String name) {
                buffer = b;
-               setThName(name);
+               setThName(th, name);
        }
 
-       public void setThName(String name) {
-               Thread.currentThread().setName(name);
+       public void setThName(Thread th, String name) {
+               th.setName(name);
        }
 
        public void run() {
                while (true) {
                        buffer.depose(new Integer(val));
-                       System.out.println (Thread.currentThread().getName() +  " a depose " + val);
+                       System.out.println(Thread.currentThread().getName() + " a depose " + val);
                        val++;
                        try {
                                Thread.sleep(ThreadLocalRandom.current().nextInt(101));
                        }
-                       catch (InterruptedException e) {}
+                       catch (InterruptedException e) {
+                               System.err.println("InterruptedException: " + e);
+                       }
                }
        }