X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD1%2Fexo3%2FConsommateur.java;h=43c811ab6895e80e7f1cfac5dc092aeadadc04c3;hb=7293fe6dc670d5164859159aab339fa3a4750773;hp=7aa8f3004d90a4ebc5fbc62e0c12f8be4d22d7ac;hpb=aee04a83cc5eecb50f85e71c4dbfc3ec2bf3cf69;p=TD_SR.git diff --git a/TD1/exo3/Consommateur.java b/TD1/exo3/Consommateur.java index 7aa8f30..43c811a 100644 --- a/TD1/exo3/Consommateur.java +++ b/TD1/exo3/Consommateur.java @@ -1,26 +1,35 @@ -import java.util.concurrent.ThreadLocalRandom; - - -public class Consommateur implements Runnable { - - private BufferCirc buffer; - - - public Consommateur(BufferCirc b) { - buffer = b; - } - - - public void run() { - Integer val; - while (true) { - val = (Integer)buffer.preleve(); - System.out.println (Thread.currentThread().getName() + " a preleve " + val); - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); - } - catch (InterruptedException e) {} - } - } - -} // fin classe Consommateur +import java.util.concurrent.ThreadLocalRandom; + + +public class Consommateur implements Runnable { + + private BufferCirc buffer; + + public Consommateur(BufferCirc b) { + buffer = b; + } + + public Consommateur(BufferCirc b, String name) { + buffer = b; + setThName(name); + } + + public void setThName(String name) { + Thread.currentThread().setName(name); + } + + public void run() { + Integer val; + while (true) { + val = (Integer)buffer.preleve(); + System.out.println (Thread.currentThread().getName() + " a preleve " + val); + try { + Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); + } + catch (InterruptedException e) { + System.out.println("InterruptedException: " + e); + } + } + } + +} // fin classe Consommateur