package com.heima.test;
public class Test2 {
/**
* 39、一共有四个售票口同时卖100张票
*/
public static void main(String[] args) {
MyTicket ms = new MyTicket();
new Thread(ms).start();
new Thread(ms).start();
new Thread(ms).start();
new Thread(ms).start();
}
}
class MyTicket extends Thread{
private static int ti = 100;
public void run(){
synchronized(MyTicket.class){
while(true){
if(ti<=0){
break;
}
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(getName()+".. 第几张"+ (ti--) +"票");
}
}
}
}
|
|