//http://www.cnblogs.com/liupengcheng
/**
* Created by Administrator on 2014/10/23.
*以下事例模拟4个窗口售100张票
*/
// 创建线程的另一种方法是声明实现 Runnable 接口的类。该类然后实现 run 方法。然后可以分配该类的实例,在创建 Thread 时作为一个参数来传递并启动。
//http://www.cnblogs.com/liupengcheng
public class ThreadDemo5 {
public static void main(String [] args){
TestThread t = new TestThread();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
}
}
//http://www.cnblogs.com/liupengcheng
class TestThread implements Runnable{ //类调用Runnable 接口的类
private int ticket = 100;
public void run()
{
while (true)
{
if(ticket>0)
System.out.println(Thread.currentThread().getName()+"is sailing ticket"+ ticket--);
}
}
}
//copyright©liupengcheng
//http://www.cnblogs.com/liupengcheng