2

Not a single operation of ArrayBlockingQueue is concurrent with any of its other operations; they always take the same lock. Even for the size() method it takes a lock.

 public int size() {
        final ReentrantLock lock = this.lock;
        lock.lock();
        try {
            return count;
        } finally {
            lock.unlock();
        }
    }

While for the implementation of LinkedBlockingQueue you have two locks: put and take. And for size() it uses AtomicInteger so doesn't need a lock.

So my question is: why is this implementation in the concurrent package - is ArrayBlockingQueue really concurrent?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
veritas
  • 2,444
  • 1
  • 21
  • 30

1 Answers1

8

ArrayBlockingQueue is in the java.util.concurrent package because multiple threads can use the object concurrently without thread-safety problems.

The ability to use multiple methods at the same time is not what the object is made for.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • 3
    I would add that the "concurrent" package is a colleciton of utils for building concurrent applications. the utils are all "thread-safe". Some are more intrinsically "concurrent" than others. – jtahlborn Jul 10 '13 at 18:31