The standard collections (ArrayList, HashMap, HashSet) are not thread-safe.
Concurrent Collections solve this by providing thread-safe implementations optimized for concurrent access.
Categories of Concurrent Collections:
Synchronized Wrappers
java.util.concurrent Package
Java provides Collections.synchronizedXxx():
List<String> syncList = Collections.synchronizedList(new ArrayList<>());
Map<String, Integer> syncMap = Collections.synchronizedMap(new HashMap<>());
These wrap normal collections with a lock around each method.
Pros: Simple, ensures thread safety.
Cons: Coarse-grained locking → can block threads unnecessarily.
Rarely used in modern high-concurrency code.
Highly concurrent collections optimized for multithreading.
Very high-performance thread-safe Map.
Multiple threads can read/write without locking the entire map.
Example usage:
ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
map.put("A", 1);
map.computeIfAbsent("B", k -> 2); // atomic update
On write operations, the collection is copied.
Excellent for read-heavy, write-light scenarios.
CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
list.add("Hello");
for (String s : list) {
System.out.println(s); // safe to iterate while adding/removing
}
Blocking queue
Used in producer-consumer scenarios
Blocking: LinkedBlockingQueue, ArrayBlockingQueue (used in producer-consumer scenarios)
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
queue.put(1); // blocks if full
int val = queue.take(); // blocks if empty
Lock-free double-ended queue for high-throughput async tasks.
Supports both FIFO and LIFO efficiently.
java.util.concurrent
│
├─── ConcurrentMap
│ ├── ConcurrentHashMap
│ └── ConcurrentSkipListMap (sorted, concurrent)
│
├─── BlockingQueue
│ ├── ArrayBlockingQueue (bounded, FIFO)
│ ├── LinkedBlockingQueue (optional bound, FIFO)
│ ├── PriorityBlockingQueue (unbounded, priority-based)
│ ├── DelayQueue (delayed scheduling)
│ └── SynchronousQueue (handoff, no capacity)
│
├─── BlockingDeque
│ └── LinkedBlockingDeque (double-ended blocking queue)
│
├─── Queue
│ ├── ConcurrentLinkedQueue (lock-free, non-blocking FIFO)
│ └── LinkedTransferQueue (hybrid blocking / transfer queue)
│
├─── Deque
│ └── ConcurrentLinkedDeque (lock-free, double-ended)
│
├─── CopyOnWrite Collections
│ ├── CopyOnWriteArrayList
│ └── CopyOnWriteArraySet
│
└─── ConcurrentNavigableMap
└── ConcurrentSkipListMap (sorted, navigable)