correction de bug, normalement tout marche + rapport
This commit is contained in:
28
rapport.txt
Normal file
28
rapport.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
Nous avons la Class Au_Wok qui contient le main(), on y initialise lesclients
|
||||||
|
ainsi que le restaurant, puis on start tous les clients.
|
||||||
|
|
||||||
|
Le constructeur Restaurant initialise le Buffet, un tableau de 4 Compartiment
|
||||||
|
(poisson, viande, légume et nouille), le stand de cuisson, l'Employe_du_buffet
|
||||||
|
et le Cuisinier. Il star en suite start ces deux derniers.
|
||||||
|
|
||||||
|
Le run de Client va suivre ces étapes :
|
||||||
|
(1) Entrer dans le restaurant en vérifiant bien que le restaurant est libre
|
||||||
|
(2) Prendre une portion de chaque Compartiment du buffet, en vérifiant
|
||||||
|
le verrou du compartiment est libre avant de lui-même le verrouiller, après
|
||||||
|
c'être servi il déverrouille fait un notifyAll pour réveiller les clients
|
||||||
|
ou l'employer du buffet qui pourrait attendre.
|
||||||
|
(3) Cuire au stand, en se mettant dans la queue (il notifyAll le stand pour
|
||||||
|
réveiller le cuisinier), quand son plat est cuit le cuisinier le sort de la
|
||||||
|
queue (le stand fait un notifyAll pour réveiller le client)
|
||||||
|
(4) Manger
|
||||||
|
(5) Sort, en faisant un notifyAll sur le restaurant pour prévenir tout autre
|
||||||
|
thread client attendant pour entrer
|
||||||
|
|
||||||
|
Le run du cuisinier, fait une boucle pour vérifier si un client est présent en
|
||||||
|
tête de la queue du stand de cuisson. Si oui, alors il fait cuire son plat.
|
||||||
|
Une fois fini, il sort le client le la queue et fait faire un notifyAll au stand
|
||||||
|
pour prévenir le client que son plat est fini.
|
||||||
|
|
||||||
|
L'employer du buffet fait le tour de chaque compartiment du buffet, s'il y a un
|
||||||
|
un buffet à moins de 100g alors il vérifie qu'il est libre (se met en wait sinon)
|
||||||
|
et le remplit.
|
||||||
10
src/Au_Wok.java
Normal file
10
src/Au_Wok.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
public class Au_Wok {
|
||||||
|
public static void main(String[] args){
|
||||||
|
Client[] clients= new Client[30];
|
||||||
|
Restaurant restaurant =new Restaurant();
|
||||||
|
for(int i=0; i<clients.length; i++){
|
||||||
|
clients[i] = new Client(i,restaurant);
|
||||||
|
clients[i].start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
public class Au_Woke {
|
|
||||||
private Client[] clients;
|
|
||||||
private Restaurant restaurant;
|
|
||||||
Au_Woke(){
|
|
||||||
clients= new Client[4];
|
|
||||||
restaurant =new Restaurant();
|
|
||||||
restaurant.cuisinier.start();
|
|
||||||
restaurant.employeB.start();
|
|
||||||
for(int i=0; i<clients.length; i++){
|
|
||||||
clients[i] = new Client(i,restaurant);
|
|
||||||
clients[i].start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public static void main(String[] args){
|
|
||||||
new Au_Woke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ public class Client extends Thread {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
try{
|
try{
|
||||||
entrer();
|
entrer();
|
||||||
@@ -44,7 +43,7 @@ public class Client extends Thread {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
compartiment.setLibre(true);
|
compartiment.setLibre(true);
|
||||||
System.out.println("Client " + this.id + " : a pris une portion de " + compartiment.getName());
|
System.out.println(this.getNameClient() + " : a pris une portion de " + compartiment.getName());
|
||||||
|
|
||||||
compartiment.notifyAll();
|
compartiment.notifyAll();
|
||||||
}
|
}
|
||||||
@@ -56,9 +55,8 @@ public class Client extends Thread {
|
|||||||
while(!restaurant.libre()){
|
while(!restaurant.libre()){
|
||||||
restaurant.wait();
|
restaurant.wait();
|
||||||
}
|
}
|
||||||
System.out.println("Client " + this.id + " : est entré dans le restaurant");
|
System.out.println("+ " + this.getNameClient() + " : est entré dans le restaurant");
|
||||||
restaurant.ajouterClient();
|
restaurant.ajouterClient();
|
||||||
restaurant.notifyAll();
|
|
||||||
}catch (InterruptedException e) {
|
}catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -67,7 +65,7 @@ public class Client extends Thread {
|
|||||||
|
|
||||||
public void manger(){
|
public void manger(){
|
||||||
try{
|
try{
|
||||||
System.out.println("Client " + this.id + " : mange");
|
System.out.println(this.getNameClient() + " : mange");
|
||||||
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){
|
||||||
@@ -77,41 +75,29 @@ public class Client extends Thread {
|
|||||||
|
|
||||||
public void sort(){
|
public void sort(){
|
||||||
synchronized(restaurant){
|
synchronized(restaurant){
|
||||||
System.out.println("Client " + this.id + " : sorti");
|
System.out.println("- " + this.getNameClient() + " : sorti");
|
||||||
restaurant.diminuerClient();
|
restaurant.diminuerClient();
|
||||||
restaurant.notifyAll();
|
restaurant.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cuir_au_stand(Stand_de_cuisson stand){
|
public void cuir_au_stand(Stand_de_cuisson stand){
|
||||||
synchronized(stand){
|
|
||||||
stand.ajouter_client(this);
|
stand.ajouter_client(this);
|
||||||
System.out.println("Client " + this.id + " : attend pour faire cuir son plat");
|
System.out.println(this.getNameClient() + " : attend pour faire cuir son plat");
|
||||||
try{
|
synchronized(stand){
|
||||||
while(stand.containsClient(this)){
|
try{
|
||||||
stand.wait();
|
while(stand.containsClient(this)){
|
||||||
|
stand.wait();
|
||||||
|
}
|
||||||
|
}catch (InterruptedException e){
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}catch (InterruptedException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
System.out.println("Client " + this.id + " : le plat est cuit");
|
System.out.println(this.getNameClient() + " : le plat est cuit");
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
try{
|
|
||||||
while (stand.attendClient()!= this) { //Verify s'il est meme client
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
System.out.println("Client " + this.id + " : fait cuir son plat");
|
|
||||||
stand.finir_cuit(this);
|
|
||||||
}catch (InterruptedException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNameClient(){
|
public String getNameClient(){
|
||||||
return ("client " + this.id);
|
return ("Client " + this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,26 @@ public class Cuisinier extends Thread {
|
|||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
while(Thread.currentThread().isDaemon()){
|
while(Thread.currentThread().isDaemon()){
|
||||||
Client client= stand.getClient();
|
attendreClient();
|
||||||
if(client!= null){
|
|
||||||
faire_cuire(client);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void attendreClient(){
|
||||||
|
Client client = stand.getClient();
|
||||||
|
synchronized(stand){
|
||||||
|
try{
|
||||||
|
while(client==null){
|
||||||
|
stand.wait();
|
||||||
|
client= stand.getClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(InterruptedException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
faire_cuire(client);
|
||||||
|
}
|
||||||
|
|
||||||
public void faire_cuire(Client client){
|
public void faire_cuire(Client client){
|
||||||
System.out.println("Cuisinier : fait cuire le plat de " + client.getNameClient()) ;
|
System.out.println("Cuisinier : fait cuire le plat de " + client.getNameClient()) ;
|
||||||
try{
|
try{
|
||||||
@@ -27,7 +40,7 @@ public class Cuisinier extends Thread {
|
|||||||
}
|
}
|
||||||
System.out.println("Cuisinier : a fini de cuire le plat de " + client.getNameClient()) ;
|
System.out.println("Cuisinier : a fini de cuire le plat de " + client.getNameClient()) ;
|
||||||
stand.nextClient();
|
stand.nextClient();
|
||||||
stand.finir_cuit(client);
|
stand.finir_cuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,12 @@ public class Restaurant {
|
|||||||
this.buffet[2] = new Compartiment("légume");
|
this.buffet[2] = new Compartiment("légume");
|
||||||
this.buffet[3] = new Compartiment("nouille");
|
this.buffet[3] = new Compartiment("nouille");
|
||||||
|
|
||||||
this.employeB = new Employe_du_buffet(buffet);
|
|
||||||
this.stand_de_cuisson = new Stand_de_cuisson();
|
this.stand_de_cuisson = new Stand_de_cuisson();
|
||||||
|
|
||||||
|
this.employeB = new Employe_du_buffet(buffet);
|
||||||
this.cuisinier = new Cuisinier(stand_de_cuisson);
|
this.cuisinier = new Cuisinier(stand_de_cuisson);
|
||||||
|
this.employeB.start();
|
||||||
|
this.cuisinier.start();
|
||||||
}
|
}
|
||||||
public synchronized boolean libre(){
|
public synchronized boolean libre(){
|
||||||
return (MAX_CLIENTS>nbClient);
|
return (MAX_CLIENTS>nbClient);
|
||||||
|
|||||||
@@ -4,19 +4,6 @@ import java.util.Queue;
|
|||||||
public class Stand_de_cuisson {
|
public class Stand_de_cuisson {
|
||||||
private Queue<Client> clients = new LinkedList<Client>();
|
private Queue<Client> clients = new LinkedList<Client>();
|
||||||
|
|
||||||
/*
|
|
||||||
* retourne le client qui est en tête de queue et le supprime de la queue
|
|
||||||
*/
|
|
||||||
public synchronized Client getNextClient2(){
|
|
||||||
while(clients.isEmpty()){
|
|
||||||
try{
|
|
||||||
wait();
|
|
||||||
}catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return clients.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
//get le client en tête de queue
|
//get le client en tête de queue
|
||||||
public synchronized Client getClient(){
|
public synchronized Client getClient(){
|
||||||
@@ -28,13 +15,13 @@ public class Stand_de_cuisson {
|
|||||||
clients.poll();
|
clients.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void finir_cuit(Client client){
|
public synchronized void finir_cuit(){
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void ajouter_client(Client client){
|
public synchronized void ajouter_client(Client client){
|
||||||
clients.add(client);
|
clients.add(client);
|
||||||
notify();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean containsClient(Client client){
|
public synchronized boolean containsClient(Client client){
|
||||||
|
|||||||
Reference in New Issue
Block a user