java---TestThread(4)

来源:互联网 发布:最精准的足彩数据分析 编辑:程序博客网 时间:2024/06/06 08:52
//模拟火车站售票窗口,开启三个窗口售票,总票数为100张
public class TestWindow {
public static void main(String[] args) {
Window w = new Window();
Window w1 = new Window();
Window w2 = new Window();
w.setName("窗口1");
w.start();
w1.setName("窗口2");
w1.start();
w2.setName("窗口3");
w2.start();


}


}
class Window extends Thread{
static int ticket = 100;
public void run(){
while(true){
if(ticket > 0){
System.out.println(Thread.currentThread().getName() +
"售票,票号是:" + ticket--);
}else{
break;
}
}
}
}
原创粉丝点击