TD2: Add response about serialization.
[TD_SR.git] / TD1 / exo3 / Consommateur.java
1 import java.util.concurrent.ThreadLocalRandom;
2
3
4 public class Consommateur implements Runnable {
5
6 private BufferCirc buffer;
7
8 public Consommateur(BufferCirc b) {
9 buffer = b;
10 }
11
12 public Consommateur(BufferCirc b, String name) {
13 buffer = b;
14 setThName(name);
15 }
16
17 public void setThName(String name) {
18 Thread.currentThread().setName(name);
19 }
20
21 public void run() {
22 Integer val;
23 while (true) {
24 val = (Integer)buffer.preleve();
25 System.out.println(Thread.currentThread().getName() + " a preleve " + val);
26 try {
27 Thread.sleep(ThreadLocalRandom.current().nextInt(1001));
28 }
29 catch (InterruptedException e) {
30 System.err.println("InterruptedException: " + e);
31 }
32 }
33 }
34
35 } // fin classe Consommateur