X-Git-Url: https://git.piment-noir.org/?p=TD_SR.git;a=blobdiff_plain;f=TD1%2Fexo3%2FProducteur.java;h=0ad13c3e2490ffc08eee619011e8809b68d2b02b;hp=d836af2a754f29d0d25d76e0413cf456cbe0e99b;hb=ce28a0211974450cf5df46e2065fb39350e029ec;hpb=aee04a83cc5eecb50f85e71c4dbfc3ec2bf3cf69 diff --git a/TD1/exo3/Producteur.java b/TD1/exo3/Producteur.java index d836af2..0ad13c3 100644 --- a/TD1/exo3/Producteur.java +++ b/TD1/exo3/Producteur.java @@ -1,27 +1,37 @@ -import java.util.concurrent.ThreadLocalRandom; - - -public class Producteur implements Runnable { - - private BufferCirc buffer; - private int val; - - - public Producteur(BufferCirc b) { - buffer = b; - } - - - public void run() { - while (true) { - buffer.depose(new Integer(val)); - System.out.println (Thread.currentThread().getName() + " a depose " + val); - val++; - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(101)); - } - catch (InterruptedException e) {} - } - } - -} // fin classe Producteur +import java.util.concurrent.ThreadLocalRandom; + + +public class Producteur implements Runnable { + + private BufferCirc buffer; + private int val; + + + public Producteur(BufferCirc b) { + 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) { + buffer.depose(new Integer(val)); + System.out.println (Thread.currentThread().getName() + " a depose " + val); + val++; + try { + Thread.sleep(ThreadLocalRandom.current().nextInt(101)); + } + catch (InterruptedException e) { + System.err.println("InterruptedException: " + e); + } + } + } + +} // fin classe Producteur