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){
|
synchronized(compartiment){
|
||||||
int r =new Random().nextInt(MAX_PORTION);
|
int r =new Random().nextInt(MAX_PORTION);
|
||||||
try{
|
try{
|
||||||
while(r > compartiment.getQuantite() && !compartiment.isLibre()){ //todo compartiment déjà occupé ?
|
while(r > compartiment.getQuantite() || !compartiment.isLibre()){
|
||||||
compartiment.wait();
|
compartiment.wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e){
|
} catch (InterruptedException e){
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ public class Compartiment{
|
|||||||
private boolean libre;
|
private boolean libre;
|
||||||
|
|
||||||
Compartiment(String name){
|
Compartiment(String name){
|
||||||
quantite_courant = 500;
|
this.quantite_courant = 500;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.libre = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void remplir(){
|
synchronized void remplir(){
|
||||||
quantite_courant = QUANTITE_MAX;
|
quantite_courant = QUANTITE_MAX;
|
||||||
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void servir(int qte){
|
synchronized void servir(int qte){
|
||||||
|
|||||||
@@ -31,16 +31,15 @@ public class Cuisinier extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void faire_cuire(Client client){
|
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{
|
try{
|
||||||
long temps_cuire =new Random().nextInt(300 - 100) + 100;
|
long temps_cuire =new Random().nextInt(300 - 100) + 100;
|
||||||
Thread.sleep(temps_cuire);
|
Thread.sleep(temps_cuire);
|
||||||
}catch(InterruptedException e){
|
}catch(InterruptedException e){
|
||||||
e.printStackTrace();
|
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.nextClient();
|
||||||
stand.finir_cuit();
|
stand.finir_cuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ public class Employe_du_buffet extends Thread{
|
|||||||
buffet[i].wait();
|
buffet[i].wait();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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();
|
buffet[i].remplir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ public class Restaurant {
|
|||||||
return (MAX_CLIENTS>nbClient);
|
return (MAX_CLIENTS>nbClient);
|
||||||
}
|
}
|
||||||
public synchronized void ajouterClient(){
|
public synchronized void ajouterClient(){
|
||||||
if(nbClient<MAX_CLIENTS){
|
|
||||||
nbClient++;
|
nbClient++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void diminuerClient(){
|
public synchronized void diminuerClient(){
|
||||||
|
|||||||
Reference in New Issue
Block a user