Files
tp-4-wok/src/Stand_de_cuisson.java
2024-12-07 12:37:03 +01:00

44 lines
1.0 KiB
Java

import java.util.LinkedList;
import java.util.Queue;
public class Stand_de_cuisson {
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
public synchronized Client getClient(){
return clients.peek();
}
//supprime le client en tête de queue
public synchronized void nextClient(){
clients.poll();
}
public synchronized void finir_cuit(Client client){
notifyAll();
}
public synchronized void ajouter_client(Client client){
clients.add(client);
notify();
}
public synchronized boolean containsClient(Client client){
return this.clients.contains(client);
}
}