TD1: fix thread name setting.
[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
2ef76f09 14 public Producteur(BufferCirc b, Thread th, String name) {
18eb400b 15 buffer = b;
2ef76f09 16 setThName(th, name);
18eb400b
JB
17 }
18
2ef76f09
JB
19 public void setThName(Thread th, String name) {
20 th.setName(name);
18eb400b
JB
21 }
22
23 public void run() {
24 while (true) {
25 buffer.depose(new Integer(val));
bdbcb0e4 26 System.out.println(Thread.currentThread().getName() + " a depose " + val);
18eb400b
JB
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