public synchronized WoTou pop() { if(index == 0) { try { this.wait(); }catch (InterruptedException e) { e.printStackTrace(); } } this.notify(); index--; return arrWT[index]; }
关于notify():
void notify() Wakes up a single thread that is waiting on this object's monitor.
notifu()函数用来唤醒正在wait的一个线程。
this.wait():
wait()使得访问当前对象的线程wait!且该对象必须为synchronized锁住,wait与sleep的区别为,wait时锁中的对象可以被访问,而sleep肯定不可以