//针对一个资源,创建多个线程来处理同一个事件,
//此处用车站售票系统·
package 课外体例;public class StationSystem {
public static void main(String[] arg)
{
Thread t = new Thread(new Tickets());
//Tickets t = new Tickets();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
Thread t3 = new Thread(t);
Thread t4 = new Thread(t);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
class Tickets implements Runnable
{
private int tickets = 1;
public void run()
{
while(true)
{
if(tickets <= 100)
System.out.println(Thread.currentThread().getName()+"销售第"+tickets+++"票");
else
break;
}
}
}
学习攻城的一只小猿,路遇大神,还望指点,谢谢!