| 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, Thread th, String name) { |
| 15 | buffer = b; |
| 16 | setThName(th, name); |
| 17 | } |
| 18 | |
| 19 | public void setThName(Thread th, String name) { |
| 20 | th.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 |