This commit is contained in:
Minh VU
2024-12-03 15:07:18 +01:00
parent aedd491b7b
commit 9452c0ea77
4 changed files with 27 additions and 25 deletions

10
.gitignore vendored
View File

@@ -1,10 +0,0 @@
# bloop and metals
.bloop
.bsp
.metals
project/metals.sbt
# vs code
.vscode
.idea

View File

@@ -29,14 +29,14 @@ public class Client extends Thread {
this.wait();
}
} catch (InterruptedException e){
throw new RuntimeException(e);
e.printStackTrace();
}
compartiment.servir(r);
try{
long temps_servir =new Random().nextInt(300 - 200) + 200;
Thread.sleep(temps_servir);
}catch(InterruptedException e){
System.out.println(e);
e.printStackTrace();
}
compartiment.notifyAll();
}
@@ -47,12 +47,12 @@ public class Client extends Thread {
try{
while(!restaurant.libre()){
this.wait();
}
}
restaurant.ajouterClient();
restaurant.notifyAll();
}catch (InterruptedException e) {
throw new RuntimeException(e);
}
restaurant.ajouterClient();
restaurant.notifyAll();
e.printStackTrace();
}
}
}
@@ -61,17 +61,28 @@ public class Client extends Thread {
long temps_manger =new Random().nextInt(2000 - 1000) + 1000;
Thread.sleep(temps_manger);
}catch(InterruptedException e){
System.out.println(e);
e.printStackTrace();
}
}
public void sort(){
restaurant.diminuerClient();
restaurant.notifyAll();
synchronized(restaurant){
restaurant.diminuerClient();
restaurant.notifyAll();
}
}
public void cuir_au_stand(Stand_de_cuisson stand){
stand.ajouter_client(this);
//TODO
synchronized(stand){
stand.ajouter_client(this);
try{
while (stand.attendClient()!= this) { //Verify s'il est meme client
wait();
}
stand.finir_cuit(this);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}

View File

@@ -21,7 +21,7 @@ public class Cuisinier extends Thread {
long temps_cuire =new Random().nextInt(300 - 100) + 100;
Thread.sleep(temps_cuire);
}catch(InterruptedException e){
System.out.println(e);
e.printStackTrace();
}
stand.finir_cuit(client);
stand.notifyAll();

View File

@@ -7,8 +7,8 @@ public class Stand_de_cuisson {
while(clients.isEmpty()){
try{
wait();
}catch (Exception e) {
System.out.println(e);
}catch (InterruptedException e) {
e.printStackTrace();
}
}
return clients.poll();
@@ -19,5 +19,6 @@ public class Stand_de_cuisson {
public synchronized void ajouter_client(Client client){
clients.add(client);
notify();
}
}