Commit | Line | Data |
---|---|---|
18eb400b JB |
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(); | |
e018d1ec | 25 | System.out.println(Thread.currentThread().getName() + " a preleve " + val); |
18eb400b JB |
26 | try { |
27 | Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); | |
28 | } | |
7293fe6d | 29 | catch (InterruptedException e) { |
ce28a021 | 30 | System.err.println("InterruptedException: " + e); |
7293fe6d | 31 | } |
18eb400b JB |
32 | } |
33 | } | |
34 | ||
35 | } // fin classe Consommateur |