TD2: Add response about serialization.
[TD_SR.git] / TD1 / exo3 / Producteur.java
1 import java.util.concurrent.ThreadLocalRandom;
2
3
4 public 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 }
31 catch (InterruptedException e) {
32 System.err.println("InterruptedException: " + e);
33 }
34 }
35 }
36
37 } // fin classe Producteur