前面讲到的ReentrantLock保证了只有一个线程可以执行临界区代码: public class Counter { private final Lock lock = new ReentrantLock(); private int counts = new int; public void inc(int index) { lock.lock(); try { counts
我们在前面已经通过ReentrantLock和Condition实现了一个BlockingQueue: public class TaskQueue { private final Lock lock = new ReentrantLock(); private final Condition condition = lock.newCondition(); private Queue<St