标签:ticket rup imp rgs 示例 catch sleep thread exception
class Ticket implements Runnable{
private int num = 100;
Object obj = new Object();
public void run(){
while(true){
synchronized(obj){
if(num>0){
try{
Thread.sleep(10);
}catch(InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"..sale.."+num--);
}
}
}
}
}
class SaleTicket{
public static void main(String[] args){
Ticket t = new Ticket();
Thread s1 = new Thread(t);
Thread s2 = new Thread(t);
Thread s3 = new Thread(t);
s1.start();
s2.start();
s3.start();
}
}
标签:ticket rup imp rgs 示例 catch sleep thread exception
原文地址:http://www.cnblogs.com/guoyunhao/p/7857077.html