4 * implementation du producteur consommateur avec un buffer circulaire
6 public class BufferCirc
{
8 private Object
[] tampon
;
10 private int prem
, der
, nbObj
;
13 public BufferCirc (int t
) {
15 tampon
= new Object
[taille
];
22 public boolean isEmpty() {
27 public boolean isFull() {
28 return nbObj
== taille
;
32 public synchronized void depose(Object obj
) {
35 System
.out
.println("Buffer is full: " + Thread
.currentThread().getName()
36 + " is waiting, size: " + nbObj
);
39 catch (InterruptedException e
) {
40 System
.err
.println("InterruptedException: " + e
);
45 prem
= (prem
+ 1) % taille
;
46 //System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);
51 public synchronized Object
preleve() {
54 System
.out
.println("Buffer is empty: " + Thread
.currentThread().getName()
55 + " is waiting, size: " + nbObj
);
58 catch (InterruptedException e
) {
59 System
.err
.println("InterruptedException: " + e
);
65 der
= (der
+ 1) % taille
;
66 //System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);
71 } // fin class BufferCirc