我正在阅读有关Condition
对象以及它们如何为每个对象提供多个等待集以及区分哪些对象或对象/线程组获得特定信号的信息。
为什么普通人Object
不这样做?例如
代替:
final Condition notFull = lock.newCondition();
final Condition notEmpty = lock.newCondition();
lock.lock();
try {
while (count == items.length)
notFull.await();
items[putptr] = x;
if (++putptr == items.length) putptr = 0;
++count;
notEmpty.signal();
我们这样做:
final Object notFull = new Object();
final Object notEmpty = new Object();
lock.lock();
try {
while (count == items.length)
notFull.wait();
items[putptr] = x;
if (++putptr == items.length) putptr = 0;
++count;
notEmpty.notify();
我们不是还有多个等待集并区分通知的线程吗?