woke
This commit is contained in:
@@ -26,7 +26,7 @@ public class Client extends Thread {
|
||||
int r =new Random().nextInt(MAX_PORTION);
|
||||
try{
|
||||
while(r > compartiment.getQuantite()){
|
||||
this.wait();
|
||||
compartiment.wait();
|
||||
}
|
||||
} catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
@@ -46,7 +46,7 @@ public class Client extends Thread {
|
||||
synchronized(restaurant){
|
||||
try{
|
||||
while(!restaurant.libre()){
|
||||
this.wait();
|
||||
restaurant.wait();
|
||||
}
|
||||
restaurant.ajouterClient();
|
||||
restaurant.notifyAll();
|
||||
|
||||
@@ -3,7 +3,7 @@ public class Compartiment{
|
||||
private int quantite_courant;
|
||||
|
||||
Compartiment(){
|
||||
quantite_courant = 0;
|
||||
quantite_courant = 500;
|
||||
}
|
||||
|
||||
synchronized void remplir(){
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
public class Restaurant {
|
||||
protected final int MAX_CLIENTS = 25;
|
||||
private int nbClient;
|
||||
|
||||
public int nbClient;
|
||||
|
||||
public Compartiment[] buffet = new Compartiment[4];
|
||||
private Employe_du_buffet employeB;
|
||||
public Employe_du_buffet employeB;
|
||||
public Stand_de_cuisson stand_de_cuisson;
|
||||
private Cuisinier cuisinier;
|
||||
public Cuisinier cuisinier;
|
||||
/*
|
||||
private Client[] clients= new Client[MAX_CLIENTS+5];
|
||||
|
||||
Restaurant(){
|
||||
@@ -25,8 +27,17 @@ public class Restaurant {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public Restaurant(){
|
||||
this.nbClient=0;
|
||||
for(int i = 0 ; i<buffet.length; i++){
|
||||
this.buffet[i] = new Compartiment();
|
||||
}
|
||||
this.employeB = new Employe_du_buffet(buffet);
|
||||
this.stand_de_cuisson = new Stand_de_cuisson();
|
||||
this.cuisinier = new Cuisinier(stand_de_cuisson);
|
||||
|
||||
|
||||
}
|
||||
public synchronized boolean libre(){
|
||||
if(nbClient>MAX_CLIENTS){
|
||||
return false;
|
||||
@@ -45,7 +56,5 @@ public class Restaurant {
|
||||
nbClient--;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
new Restaurant();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user