买火车票
package text;
public class Demo01 {
public static void main(String[] args) {
MyThread mt = new MyThread();
MyThread mt1 = new MyThread();
MyThread mt2 = new MyThread();
mt.setName("窗口1");
mt1.setName("窗口2");
mt2.setName("窗口3");
mt.start();
mt1.start();
mt2.start();
}
}
class MyThread extends Thread{
static int num=100;
public void run() {
while(true) {
if(num>0) {
System.out.println(Thread.currentThread().getName()+"卖出第"+(num--)+"张票");
}else {
break;
}
}
}
}