Commit | Line | Data |
---|---|---|
18eb400b JB |
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)); | |
e018d1ec | 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 |