Clean • Professional
ConcurrentLinkedQueue is a high-performance, thread-safe, non-blocking queue in Java.
It belongs to the java.util.concurrent package and is widely used for multi-threaded producer–consumer systems.
It uses a lock-free algorithm based on CAS (Compare-And-Swap), making it extremely fast in concurrent environments.
A ConcurrentLinkedQueue is:
It is one of the most scalable queues in the JDK.
It implements the following:
Queue
ConcurrentLinkedQueue (class)
This makes it a powerful choice for multi-producer and multi-consumer environments.
ConcurrentLinkedQueue internally uses:
1. Linked Nodes
Each element is wrapped inside a linked node (like LinkedList).
2. CAS (Compare-And-Swap) Atomic Updates
Instead of locks, it uses CAS to:
This means:
Operations like offer() and poll() run in O(1) average time.

1. Thread-Safe (Without Locks)
It achieves thread safety using atomic operations, not synchronized or ReentrantLocks.
2. FIFO Ordering
Elements are processed in the order they were inserted.
3. Unbounded Queue
It expands automatically depending on system memory.
4. High-Performance
Designed for heavily concurrent environments with minimal contention.
5. Weakly Consistent Iterators
Iteration:
6. Non-Blocking Behavior
Methods like offer(), poll(), and peek() never block.
| Method | Description |
|---|---|
| offer(e) | Adds element at the tail (always succeeds) |
| add(e) | Same as offer(), but may throw exception if fails |
| poll() | Removes and returns head, or null if empty |
| peek() | Returns head without removing (or null) |
| isEmpty() | Checks if queue is empty |
| size() | Returns count (but expensive & approximate) |
| iterator() | Returns weakly consistent iterator |
import java.util.concurrent.ConcurrentLinkedQueue;
public class Main {
public static void main(String[] args) {
ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
queue.offer("A");
queue.offer("B");
queue.offer("C");
System.out.println("Queue: " + queue);
System.out.println("Poll: " + queue.poll());
System.out.println("Poll: " + queue.poll());
System.out.println("After Poll: " + queue);
System.out.println("Peek: " + queue.peek());
}
}
Output
Queue: [A, B, C]
Poll: A
Poll: B
After Poll: [C]
Peek: C
import java.util.concurrent.ConcurrentLinkedQueue;
public class Demo {
public static void main(String[] args) {
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
Runnable producer = () -> {
for (int i = 1; i <= 5; i++) {
queue.offer(i);
}
};
Thread t1 = new Thread(producer);
Thread t2 = new Thread(producer);
t1.start();
t2.start();
}
}
Use it when you need:
| Feature | ConcurrentLinkedQueue | LinkedBlockingQueue |
|---|---|---|
| Blocking | No | Yes |
| Capacity | Unbounded | Bounded/Unbounded |
| Locking | Lock-free (CAS) | Uses locks |
| Performance | Very fast | Slower under high concurrency |
| Use Case | Non-blocking apps | Producer-consumer with waiting |
size() is slow and approximateput(), take() not available)ConcurrentLinkedQueue is ideal when:
It’s a top choice for modern concurrent systems, high-performance backends, and real-time applications.