public class Ticket extends Thread { private int ticket=100; public Ticket(){
} public Ticket(String name) { super(name); } public void run(){ while(true){ if(ticket<=0){ break; }
System.out.println(Thread.currentThread().getName()+"卖了第"+ticket+"票"); ticket--; }
}
}
public class test { public static void main(String[] args) {
Ticket w1=new Ticket("售票窗口1"); Ticket w2=new Ticket("售票窗口2"); Ticket w3=new Ticket("售票窗口3"); Ticket w4=new Ticket("售票窗口4"); w1.start(); w2.start(); w3.start(); w4.start(); }
}
全部评论
(0) 回帖