\r
\r
public synchronized void depose(Object obj) {\r
- if (!isFull()) {\r
- nbObj++;\r
- tampon[prem] = obj;\r
- prem = (prem + 1) % taille;\r
- System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);\r
- } else {\r
- System.out.println("Buffer plein pour " + Thread.currentThread().getName());\r
+ while(isFull()) {\r
+ try {\r
+ wait();\r
+ }\r
+ catch (InterruptedException e) {}\r
}\r
+ nbObj++;\r
+ tampon[prem] = obj;\r
+ prem = (prem + 1) % taille;\r
+ notify();\r
+ System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj);\r
}\r
\r
\r
public synchronized Object preleve() {\r
- Object outObj = null;\r
- if (isEmpty()) {\r
- nbObj--;\r
- outObj = tampon[der];\r
- der = (der + 1) % taille;\r
- System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);\r
- } else {\r
- System.out.println("Buffer vide pour " + Thread.currentThread().getName());\r
+ while(isEmpty()) {\r
+ try {\r
+ wait();\r
+ }\r
+ catch (InterruptedException e) {}\r
}\r
+ Object outObj = null;\r
+ nbObj--;\r
+ outObj = tampon[der];\r
+ der = (der + 1) % taille;\r
+ notify();\r
+ System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj);\r
return outObj;\r
}\r
\r