1.模拟销售类:
class ThreadTest implements Runnable { private int tickets=100; public void run() { while(true) { if(tickets>0) System.out.println(Thread.currentThread().getName() + " is saling ticket " + tickets--); } } <p>}</p>2.执行类:
public static void main(String [] args) { ThreadTest t=new ThreadTest(); new Thread(t).start(); new Thread(t).start(); new Thread(t).start(); new Thread(t).start(); }
原文:http://blog.csdn.net/ahhmdwg/article/details/42102261