package com.yuxinyicheng.test;
//通过实现Runnable的方式,模拟窗口售票,体会这种方式的优点
class Window2 implements Runnable{
int ticket =100;//不用指明为static的
public void run(){
while(true){
if(ticket >0 ){
System.out.println(Thread.currentThread().getName()+" 窗口,票号为:"+ticket--);
}
else{
break;
}
}
}
}
public class TestWindow2 {
public static void main(String[] args) {
Window2 w=new Window2();
Thread t1=new Thread(w);
Thread t2=new Thread(w);
Thread t3=new Thread(w);
t1.start();
t2.start();
t3.start();
}
}