Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What kind of queue is ConcurrentLinkedQueue, and when would you choose LinkedBlockingQueue instead?

ConcurrentLinkedQueue is an unbounded, thread-safe FIFO queue that never blocks: it is based on the Michael-Scott lock-free algorithm, so offer always succeeds at once and poll returns null when the queue is empty. Its size() walks the whole queue and is only approximate under concurrent change, so we use isEmpty(), and it does not accept null. We choose LinkedBlockingQueue instead when consumers should sleep until work arrives, using take(), or when we need a capacity bound so producers slow down or are rejected when consumers fall behind, which is backpressure.

Background to this question

Queues connect the parts of a concurrent program: request threads hand work to background workers, event sources hand events to processors, one stage of a pipeline feeds the next. The JDK offers several thread-safe queues, and the two linked ones are easy to confuse. Choosing wrongly leads to the classic problems of a busy-spinning consumer burning a core, or an unbounded queue growing until the service runs out of memory. In this answer, we will recap what thread-safe FIFO means, see how ConcurrentLinkedQueue works without locks, go through its methods and caveats, and then decide when LinkedBlockingQueue is the better choice.

1A Quick Recap of Thread-Safe Queues

A FIFO queue, first in first out, hands out elements in the order they were added. In a concurrent program, many producer threads add and many consumer threads remove at the same time, so the queue must keep its links intact and never give the same element to two consumers.

The java.util.concurrent queues answer two further questions differently. What happens when a consumer asks and the queue is empty: does it get nothing back immediately, or does it wait? And what happens when producers are faster than consumers: does the queue grow forever, or is there a limit? ConcurrentLinkedQueue answers no waiting and no limit. LinkedBlockingQueue can wait and can be bounded.

2How ConcurrentLinkedQueue Works

ConcurrentLinkedQueue is a singly linked list with a head and a tail pointer, implementing the algorithm published by Maged Michael and Michael Scott in 1996. To enqueue, a thread creates a node and uses compare-and-set, an atomic instruction that changes a reference only if it still holds the expected value, to link the node after the current last node; then it tries to swing the tail pointer forward. To dequeue, a thread uses compare-and-set to take the item out of the first node and advance the head.

If two threads race for the same spot, one compare-and-set wins and the other simply retries with fresh values. No thread ever holds a lock, so a thread that is paused by the operating system mid-operation cannot block the others; other threads even help finish a half-done tail update. That is what lock-free means, and it is why the queue scales well under heavy contention.

Java
Queue<String> q = new ConcurrentLinkedQueue<>();
q.offer("a"); // true: always succeeds, the queue is unbounded
q.offer("b"); // true
System.out.println(q.poll()); // a
System.out.println(q.poll()); // b
System.out.println(q.poll()); // null: empty, returns at once instead of waiting
System.out.println(q.isEmpty()); // true, and cheap
q.offer(null); // NullPointerException: null would be confused with empty

Notice the two facts that shape how we use it. offer never blocks and never fails, because there is no capacity. poll never blocks either; it returns null when there is nothing to take. That is also why nulls are forbidden: a null element would be indistinguishable from an empty queue.

3The Caveats: size() and Iteration

ConcurrentLinkedQueue does not keep a counter, because a shared counter would be a contention point that every offer and poll would fight over. So size() counts by walking the entire list, which is O(n), and while other threads are adding and removing, the count it returns may already be wrong when it arrives. The Javadoc warns about exactly this.

So the rule is to prefer isEmpty(), which only looks at the head and is O(1), and never to use size() in hot paths or as a guard for limits. If we need to monitor queue length, a separate LongAdder updated on offer and poll gives a cheap approximate metric. Iteration is weakly consistent like the other concurrent collections: it does not throw ConcurrentModificationException but may or may not show elements added during the walk.

4When LinkedBlockingQueue Is the Better Choice

LinkedBlockingQueue implements BlockingQueue. It uses two locks, one for the head and one for the tail, so a producer and a consumer can work at the same time, and it adds methods that wait. take() blocks until an element is available, and put() blocks while the queue is full. Created with a capacity, as in new LinkedBlockingQueue<>(10_000), it refuses to grow past it: put waits, offer returns false, and offer with a timeout waits a bounded time.

That gives us two things ConcurrentLinkedQueue cannot. First, idle consumers sleep inside take instead of polling in a loop, using no CPU while there is no work. Second, the capacity creates backpressure: when consumers fall behind, producers are slowed or told no, instead of the queue silently absorbing millions of items until the heap is exhausted. For a worker pool fed by request threads, both matter, which is why ThreadPoolExecutor takes a BlockingQueue. ConcurrentLinkedQueue fits when consumers have other work to do and check the queue opportunistically, such as an event loop draining pending tasks, or when producers must never block and the input rate is naturally bounded.

ConcurrentLinkedQueue or LinkedBlockingQueue
QuestionConcurrentLinkedQueueLinkedBlockingQueue
Empty queue on removepoll returns null at oncetake waits; poll(timeout) waits a while
CapacityUnboundedOptional bound, e.g. 10,000
Full queue on addNever fullput waits, offer returns false
LockingLock-free compare-and-setTwo locks: head and tail
size()O(n), approximateO(1), counted
Typical useNon-blocking hand-off, event loopsWorker pools, producer-consumer

5Follow-up questions

Is LinkedBlockingQueue unbounded by default?

Yes, the no-argument constructor uses Integer.MAX_VALUE as capacity, which is unbounded in practice. Executors.newFixedThreadPool uses exactly that, which is why a fixed pool can accumulate an enormous backlog. Pass an explicit capacity when you want backpressure.

What about ArrayBlockingQueue and LinkedTransferQueue?

ArrayBlockingQueue is always bounded, backed by a fixed array with one lock, and allocates no nodes per element. LinkedTransferQueue is an unbounded, mostly lock-free blocking queue that also lets a producer wait until a consumer takes its item. Each fits a slightly different trade-off.

Why does ConcurrentLinkedQueue scale better under contention?

Because no thread ever waits for another to release a lock. Under heavy contention some compare-and-set operations fail and retry, but some thread always makes progress, and a thread descheduled mid-operation does not stall the rest.

6Conclusion

In this answer, we saw that ConcurrentLinkedQueue is an unbounded, non-blocking, thread-safe FIFO queue built on the Michael-Scott lock-free algorithm. offer and poll never block, poll returns null when empty, nulls are not allowed, and size() is an O(n) walk that is only approximate under concurrent change, so isEmpty is preferred. LinkedBlockingQueue is the better choice when consumers should wait for work with take, or when a capacity bound is needed to apply backpressure on producers.

What to say in the interviewAbout 90 seconds aloud

Open with

ConcurrentLinkedQueue is an unbounded, thread-safe FIFO queue that never blocks. It's based on the Michael-Scott lock-free algorithm: it's a linked list where enqueue and dequeue use compare-and-set on the tail and head, so no thread ever holds a lock, and if two threads race, one wins and the other retries. offer always succeeds immediately because there's no capacity, and poll returns immediately, giving null if the queue is empty.

Then, if they want more

That's also why nulls aren't allowed; a null element would look like an empty queue. One caveat is size: it doesn't keep a counter, to avoid contention, so size walks the whole list, which is O(n), and the answer may be stale under concurrent change. I'd use isEmpty instead and never use size for limits.

I'd pick LinkedBlockingQueue when one of two things matters. First, if consumers should wait for work: take blocks until something arrives, so idle workers use no CPU, whereas with ConcurrentLinkedQueue you'd end up spinning on poll or adding your own back-off.

Second, if I need backpressure: with a capacity, put blocks and offer returns false when the queue is full, so producers slow down instead of the queue growing until we run out of memory.

So for worker pools and producer-consumer pipelines I'd use a bounded blocking queue, and I'd keep ConcurrentLinkedQueue for non-blocking hand-offs, like an event loop draining tasks when it has time.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What kind of queue is ConcurrentLinkedQueue, and when would you choose...": https://scrivio-interview-library.netlify.app/java/concurrent-collections/92c58a2f1b/