Use stderr where appropriate.
[TD_SR.git] / TD1 / exo3 / Producteur.java
CommitLineData
18eb400b
JB
1import java.util.concurrent.ThreadLocalRandom;
2
3
4public class Producteur implements Runnable {
5
6 private BufferCirc buffer;
7 private int val;
8
9
10 public Producteur(BufferCirc b) {
11 buffer = b;
12 }
13
14 public Producteur(BufferCirc b, String name) {
15 buffer = b;
16 setThName(name);
17 }
18
19 public void setThName(String name) {
20 Thread.currentThread().setName(name);
21 }
22
23 public void run() {
24 while (true) {
25 buffer.depose(new Integer(val));
26 System.out.println (Thread.currentThread().getName() + " a depose " + val);
27 val++;
28 try {
29 Thread.sleep(ThreadLocalRandom.current().nextInt(101));
30 }
7293fe6d 31 catch (InterruptedException e) {
ce28a021 32 System.err.println("InterruptedException: " + e);
7293fe6d 33 }
18eb400b
JB
34 }
35 }
36
37} // fin classe Producteur