Files
tp-4-wok/src/Employe_du_buffet.java

49 lines
1.7 KiB
Java

import static org.fusesource.jansi.Ansi.*;
public class Employe_du_buffet extends Thread{
public Buffet buffet;
public Employe_du_buffet(Buffet buffet){
this.buffet = buffet;
this.setDaemon(true);
}
/*
* vas faire le tour de tout les buffet
* si un a moins de 100g, si il n'est pas libre il wait dessus, sinon il le remplis
* avant de se réendormir il vérifit qu'aucun compartiment n'as été vidé pendant dans son dot
*/
public void run(){
while(Thread.currentThread().isDaemon()){
for(int i = 0; i<buffet.length();i++){
Compartiment compartiment = buffet.getCompartiment(i);
try {
compartiment.getSemaphore().acquire();
if(compartiment.getQuantite()<100){
System.out.println( ansi().fgBlue().a("Employe Buffer").reset().a(": remplie de stand " + compartiment.getName() + ", il ne restait plus que " + compartiment.getQuantite() +" g"));
//System.out.println("Employe Buffer : remplie de stand " + compartiment.getName() + ", il ne restait plus que " + compartiment.getQuantite() +" g");
compartiment.remplir();
}
} catch (Exception e) {
e.printStackTrace();
} finally{
compartiment.getSemaphore().release();
}
}
synchronized(buffet){
if(!this.buffet.isEmpty()){
try {
buffet.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}