Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- public class Barber extends Thread{
- int customer;
- boolean stopButton= false;
- String barber;
- TextArea textarea;
- int i;
- WaitRoom wr;
- MyCanvas mycanvas;
- Semaphore s;
- Semaphore delay;
- Semaphore barberGoing;
- MyPanelTop mytop;
- boolean sleep=true;
- boolean awake= false;
- boolean kill =false;
- boolean isFull=false;
- Barber(String barber, TextArea textarea, int i, WaitRoom wr, MyCanvas mycanvas, Semaphore s, Semaphore delay, Semaphore barberGoing, MyPanelTop mytop){
- this.barber= barber;
- this.textarea= textarea;
- this.i= i;
- this.wr= wr;
- this.mycanvas= mycanvas;
- this.s= s;
- this.delay= delay;
- this.barberGoing= barberGoing;
- this.mytop = mytop;
- }//end constructor
- public synchronized void run(){
- while(true) {
- try {
- s.P();
- isFull = wr.isFull();
- if (wr.isEmpty()) {
- s.V();
- wr.setBarberGoingToSleep(sleep);
- mytop.debugAppend("Barber is going to sleep!");
- delay.P();
- wr.setBarberGoingToSleep(awake);
- s.P();
- }
- wr.removeCust();
- mycanvas.moveToChair();
- if (isFull) {
- delay.V();
- }
- s.V();
- sleep(mytop.getCutTime());
- mycanvas.showCustomerLeave();
- if(kill){
- barberGoing.P();
- }
- } catch (Exception e) {
- return;
- }
- }
- }//end run
- public void barberButton(boolean action){this.kill = action;}
- }//end Barber
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement