package ShouPiao;
public class TicketSeller extends Thread {
static int num=100;
public TicketSeller(String name) {
super(name);
// TODO Auto-generated constructor stub
}
public void run() {
while (true) {
synchronized (TicketSeller.class) {
if (num!=0) {
System.out.println(getName()+"机售出"+(num--)+"张票");
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|
|