public class Demo2 implements Runnable {
int i=0;
@Override
public void run() {
while (true) {
synchronized (this) {
notify();
if (i < 100) {
i++;
System.out.println(Thread.currentThread().getName() + "票号是:" + i);
} else {
break;
}
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
Demo2 demo2=new Demo2();
Thread t1=new Thread(demo2,"线程1售出的");
Thread t2=new Thread(demo2,"线程2售出的");
Thread t3=new Thread(demo2,"线程3售出的");
t1.start();
t2.start();
t3.start();
}
}