多线程实例练习

卖票

class TicketWindow2 implements Runnable{
private int tickets=100;
public void run();{
while(true){
if(tickets>0){
System.out.println(Thread.currentThread().getName());
}
}
}
}
public calss Example{
public static void main(String args[]){
TicketWindow2 tw=new TicketWindow();
new Thread(tw,“窗口1”).start();
new Thread(tw,“窗口2”).start();
new Thread(tw,“窗口3”).start();
new Thread(tw,“窗口4”).start();
}
}