This commit is contained in:
Minh VU
2024-12-03 16:28:22 +01:00
parent f47f77dc00
commit da7acb79c4
3 changed files with 6 additions and 11 deletions

View File

@@ -52,7 +52,7 @@ public class Client extends Thread {
while(!restaurant.libre()){ while(!restaurant.libre()){
restaurant.wait(); restaurant.wait();
} }
System.out.println("Clien " + Thread.currentThread().getId() + " : est entré dans le restaurant"); System.out.println("Client " + Thread.currentThread().getId() + " : est entré dans le restaurant");
restaurant.ajouterClient(); restaurant.ajouterClient();
restaurant.notifyAll(); restaurant.notifyAll();
}catch (InterruptedException e) { }catch (InterruptedException e) {

View File

@@ -9,7 +9,8 @@ public class Cuisinier extends Thread {
} }
public void run(){ public void run(){
while(Thread.currentThread().isDaemon()){ while(Thread.currentThread().isDaemon()){
//while(true){
Client client= stand.attendClient(); Client client= stand.attendClient();
if(client!= null){ if(client!= null){
faire_cuire(client); faire_cuire(client);

View File

@@ -1,5 +1,5 @@
public class Restaurant { public class Restaurant {
protected final int MAX_CLIENTS = 25; protected final int MAX_CLIENTS = 4;
public int nbClient; public int nbClient;
@@ -41,11 +41,7 @@ public class Restaurant {
} }
public synchronized boolean libre(){ public synchronized boolean libre(){
if(nbClient>MAX_CLIENTS){ return (MAX_CLIENTS>nbClient);
return false;
}else {
return true;
}
} }
public synchronized void ajouterClient(){ public synchronized void ajouterClient(){
if(nbClient<MAX_CLIENTS){ if(nbClient<MAX_CLIENTS){
@@ -54,9 +50,7 @@ public class Restaurant {
} }
public synchronized void diminuerClient(){ public synchronized void diminuerClient(){
if(nbClient>MAX_CLIENTS){ nbClient--;
nbClient--;
}
} }
} }