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(); this.wait();
} }
} catch (InterruptedException e){ } catch (InterruptedException e){
throw new RuntimeException(e); e.printStackTrace();
} }
compartiment.servir(r); compartiment.servir(r);
try{ try{
long temps_servir =new Random().nextInt(300 - 200) + 200; long temps_servir =new Random().nextInt(300 - 200) + 200;
Thread.sleep(temps_servir); Thread.sleep(temps_servir);
}catch(InterruptedException e){ }catch(InterruptedException e){
System.out.println(e); e.printStackTrace();
} }
compartiment.notifyAll(); compartiment.notifyAll();
} }
@@ -47,12 +47,12 @@ public class Client extends Thread {
try{ try{
while(!restaurant.libre()){ while(!restaurant.libre()){
this.wait(); this.wait();
} }
restaurant.ajouterClient();
restaurant.notifyAll();
}catch (InterruptedException e) { }catch (InterruptedException e) {
throw new RuntimeException(e); e.printStackTrace();
} }
restaurant.ajouterClient();
restaurant.notifyAll();
} }
} }
@@ -61,17 +61,28 @@ public class Client extends Thread {
long temps_manger =new Random().nextInt(2000 - 1000) + 1000; long temps_manger =new Random().nextInt(2000 - 1000) + 1000;
Thread.sleep(temps_manger); Thread.sleep(temps_manger);
}catch(InterruptedException e){ }catch(InterruptedException e){
System.out.println(e); e.printStackTrace();
} }
} }
public void sort(){ public void sort(){
restaurant.diminuerClient(); synchronized(restaurant){
restaurant.notifyAll(); restaurant.diminuerClient();
restaurant.notifyAll();
}
} }
public void cuir_au_stand(Stand_de_cuisson stand){ public void cuir_au_stand(Stand_de_cuisson stand){
stand.ajouter_client(this); synchronized(stand){
//TODO 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; long temps_cuire =new Random().nextInt(300 - 100) + 100;
Thread.sleep(temps_cuire); Thread.sleep(temps_cuire);
}catch(InterruptedException e){ }catch(InterruptedException e){
System.out.println(e); e.printStackTrace();
} }
stand.finir_cuit(client); stand.finir_cuit(client);
stand.notifyAll(); stand.notifyAll();

View File

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