1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public class GestionSalon implements Runnable
{
private int tempsTraitement;
private int tempsClient;
private int nombreClient;
private IhmSalon monIhm;
private Semaphore siege;
private ArrayList<Client> listeClient;
GestionSalon(IhmSalon monIhm)
{
siege=new Semaphore(3);
this.monIhm=monIhm;
tempsTraitement=monIhm.getTempsTraitement();
tempsClient=monIhm.getTempsClient();
listeClient=new ArrayList<Client>();
nombreClient=0;
}
public void coiffer(int numeroClientcourant)
{
try {
siege.acquire();
listeClient.get(numeroClientcourant).setSiegePris(monIhm.prendreSiege());
listeClient.get(numeroClientcourant).pause(10000);
monIhm.libererSiege( listeClient.get(numeroClientcourant).getSiegePris());
siege.release();
} catch (InterruptedException ex) {
Logger.getLogger(GestionSalon.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void pause(int temps)
{
try {
Thread.currentThread().sleep(temps);
} catch (InterruptedException ex) {
Logger.getLogger(GestionSalon.class.getName()).log(Level.SEVERE, null, ex);
}
}
// c'est ici que les thread sont cree
public void run() {
Client tamponClient;
while(true)
{
tamponClient=new Client(this);
tamponClient.setNumeroClient(nombreClient);
listeClient.add(nombreClient,tamponClient);
nombreClient++;
tamponClient.run();
tamponClient=null;
pause(3*1000);
}
}
} |
Partager