X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD1%2Fexo3%2FProducteur.java;h=f7f3c474b57e49d830ec32e6aeed80fff028d915;hb=d3ae3c42030dcfc0d1de38673f221c7618863ca9;hp=10eab6d55ec99bc5e25278842a1b1a5e30a6a8a6;hpb=396bc7433aa7fc3c404f2d175d1c93b82791cdde;p=TD_SR.git diff --git a/TD1/exo3/Producteur.java b/TD1/exo3/Producteur.java index 10eab6d..f7f3c47 100644 --- a/TD1/exo3/Producteur.java +++ b/TD1/exo3/Producteur.java @@ -1,3 +1,4 @@ +import java.util.concurrent.ThreadLocalRandom; public class Producteur implements Runnable { @@ -10,6 +11,14 @@ public class Producteur implements Runnable { buffer = b; } + public Producteur(BufferCirc b, String name) { + buffer = b; + setThName(name); + } + + public void setThName(String name) { + Thread.currentThread().setName(name); + } public void run() { while (true) { @@ -17,7 +26,7 @@ public class Producteur implements Runnable { System.out.println (Thread.currentThread().getName() + " a depose " + val); val++; try { - Thread.sleep((int)(Math.random()*100)); + Thread.sleep(ThreadLocalRandom.current().nextInt(101)); } catch (InterruptedException e) {} }