Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Collections Deep Dive — List, Set, Map, Queue

Why is ConcurrentModificationException best-effort, and how do concurrent collections differ from synchronized wrappers?

Level III · MidCollections Deep Dive — List, Set, Map, Queue
Short answer

CME comes from a fail-fast modCount check meant to catch single-thread bugs, but it's documented as best-effort, so you can't rely on it to detect every concurrent misuse.

Explanation

Collections.synchronizedMap wraps every method in a lock, giving coarse mutual exclusion but you still must externally synchronize iteration and it serializes all access. ConcurrentHashMap instead allows concurrent reads and fine-grained (bucket/bin-level) updates with weakly-consistent iterators that never throw CME, which is why it scales far better under contention.

Common mistakes
  • Relying on ConcurrentModificationException to detect races.
  • Thinking Collections.synchronizedList makes iteration thread-safe.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Collections Deep Dive — List, Set, Map, Queue.

Practise free

More on Collections Deep Dive — List, Set, Map, Queue