This commit is contained in:
Minh VU
2024-12-03 15:46:47 +01:00
parent 1b7ad1b32f
commit 13fd189dc7
4 changed files with 35 additions and 10 deletions

16
Au_Woke.java Normal file
View File

@@ -0,0 +1,16 @@
public class Au_Woke {
private Client[] clients= new Client[30];
private Restaurant restaurant =new Restaurant();
Au_Woke(){
restaurant.cuisinier.start();
restaurant.employeB.start();
for(int i=0; i<clients.length; i++){
clients[i] = new Client(restaurant);
clients[i].start();
}
}
public static void main(String[] args){
new Au_Woke();
}
}

View File

@@ -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();

View File

@@ -3,7 +3,7 @@ public class Compartiment{
private int quantite_courant;
Compartiment(){
quantite_courant = 0;
quantite_courant = 500;
}
synchronized void remplir(){

View File

@@ -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();
}
}