标签:
class Threadsale implements Runnable{
int tickets = 100;
public void run(){
while(true){
if(tickets>0){
System.out.println(Thread.currentThread().getName()+"售车票第"+tickets--+"号");
}
else
System.exit(0);
}
}
}
public class DemoThread {
public static void main(String[] args){
Threadsale t=new Threadsale();//实例化线程
Thread t1=new Thread(t,"第1号售票窗口");
Thread t2=new Thread(t,"第2号售票窗口");
Thread t3=new Thread(t,"第3号售票窗口");
Thread t4=new Thread(t,"第4号售票窗口");
t1.start();
t2.start();
t3.start();
t4.start();
}
}
运行结果为:
标签:
原文地址:http://blog.csdn.net/wintersense/article/details/42027715