public class TextThread2{
public static void main(String[] args){
Thread t1=new Thread(new Text21());
t1.setName("售票窗口1"); t1.start();
Thread t2=new Thread(new Text21());
t2.setName("售票窗口2"); t2.start();
Thread t3=new Thread(new Text21());
t3.setName("售票窗口3"); t3.start();
}
}
class Text21 implements Runnable{
public static int nums1=100;
static String ss=new String("11");
public void run() {
while(true){
synchronized(ss){
if(nums1>0){
System.out.println(Thread.currentThread().getName()+"卖出了第:"+(101-nums1)+"票。");
--nums1 ;
}else{
break;
}
}
}
}
} |
|