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?

1
  • 4
    It can be used in a concurrent setting---that's the point. Commented Jul 10, 2013 at 18:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.