<strong>富而可求也,虽执鞭之士,吾亦为之。如不可求,从吾所好。——孔子《论语》</strong>
public static void main(String[] args) {
Thread t = new my();
t.setName("实体店");
t.start();
Thread t1 = new my();
t1.setName("官网店");
t1.start();
}
}
class my extends Thread {
static int x = 100;
@Override
public void run() {
int i=0;
int y =0;
while(true) {
synchronized (my.class) {
if(x<=0)
break;
if(this.getName().equals("实体店")){
i++;
}else{
y++;
}
System.out.println(this.getName()+"卖出"+(101-x--)+"剩余"+x);
}
}
if("实体店".equals(this.getName())){
System.out.println("实体店"+i);
}else{
System.out.println("官网店"+y);
}
}