在阅读 的源代码时ArrayBlockingQueue
,我发现一条评论解释说它使用了“任何教科书中都可以找到的经典双条件算法”:
/*
* Concurrency control uses the classic two-condition algorithm
* found in any textbook.
*/
/** Main lock guarding all access */
private final ReentrantLock lock;
/** Condition for waiting takes */
private final Condition notEmpty;
/** Condition for waiting puts */
private final Condition notFull;
为什么它使用经典的二条件(notEmpty,notFull)算法?