correction bug compartiment (init libre a true, et boucle while avec un ||, manquait aussi un notifyAll après avoir rempli un compartiment)
This commit is contained in:
@@ -28,7 +28,7 @@ public class Client extends Thread {
|
||||
synchronized(compartiment){
|
||||
int r =new Random().nextInt(MAX_PORTION);
|
||||
try{
|
||||
while(r > compartiment.getQuantite() && !compartiment.isLibre()){ //todo compartiment déjà occupé ?
|
||||
while(r > compartiment.getQuantite() || !compartiment.isLibre()){
|
||||
compartiment.wait();
|
||||
}
|
||||
} catch (InterruptedException e){
|
||||
|
||||
@@ -5,12 +5,14 @@ public class Compartiment{
|
||||
private boolean libre;
|
||||
|
||||
Compartiment(String name){
|
||||
quantite_courant = 500;
|
||||
this.quantite_courant = 500;
|
||||
this.name = name;
|
||||
this.libre = true;
|
||||
}
|
||||
|
||||
synchronized void remplir(){
|
||||
quantite_courant = QUANTITE_MAX;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
synchronized void servir(int qte){
|
||||
|
||||
@@ -31,16 +31,15 @@ public class Cuisinier extends Thread {
|
||||
}
|
||||
|
||||
public void faire_cuire(Client client){
|
||||
System.out.println("Cuisinier : fait cuire le plat de " + client.getNameClient()) ;
|
||||
System.out.println("# Cuisinier : fait cuire le plat de " + client.getNameClient()) ;
|
||||
try{
|
||||
long temps_cuire =new Random().nextInt(300 - 100) + 100;
|
||||
Thread.sleep(temps_cuire);
|
||||
}catch(InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Cuisinier : a fini de cuire le plat de " + client.getNameClient()) ;
|
||||
System.out.println("# Cuisinier : a fini de cuire le plat de " + client.getNameClient()) ;
|
||||
stand.nextClient();
|
||||
stand.finir_cuit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ public class Employe_du_buffet extends Thread{
|
||||
buffet[i].wait();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Employe Buffer : remplie de stand " + i);
|
||||
System.out.println("Employe Buffer : remplie de stand " + buffet[i].getName() + ", il ne restait plus que " + buffet[i].getQuantite() +" g");
|
||||
buffet[i].remplir();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,8 @@ public class Restaurant {
|
||||
return (MAX_CLIENTS>nbClient);
|
||||
}
|
||||
public synchronized void ajouterClient(){
|
||||
if(nbClient<MAX_CLIENTS){
|
||||
nbClient++;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void diminuerClient(){
|
||||
nbClient--;
|
||||
|
||||
Reference in New Issue
Block a user