TD1: Make some constructors.
[TD_SR.git] / TD1 / exo3 / Producteur.java
index 10eab6d55ec99bc5e25278842a1b1a5e30a6a8a6..f7f3c474b57e49d830ec32e6aeed80fff028d915 100644 (file)
@@ -1,3 +1,4 @@
+import java.util.concurrent.ThreadLocalRandom;\r
 \r
 \r
 public class Producteur implements Runnable {\r
@@ -10,6 +11,14 @@ public class Producteur implements Runnable {
                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
@@ -17,7 +26,7 @@ public class Producteur implements Runnable {
                        System.out.println (Thread.currentThread().getName() +  " a depose " + val);\r
                        val++;\r
                        try {\r
-                               Thread.sleep((int)(Math.random()*100));\r
+                               Thread.sleep(ThreadLocalRandom.current().nextInt(101));\r
                        }\r
                        catch (InterruptedException e) {}\r
                }\r