首页 > 代码库 > 多线程模拟销售火车票

多线程模拟销售火车票



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();

}


多线程模拟销售火车票