In this lecture, we’ll look at why regular collections (
ArrayList,
HashMap) are dangerous in a multithreaded environment, and which thread-safe alternatives the
java.util.concurrent package provides:
ConcurrentHashMap,
CopyOnWriteArrayList,
ConcurrentLinkedQueue, skip-list–based structures, and
BlockingQueue. We’ll discuss atomic operations like
merge,
putIfAbsent,
computeIfAbsent, compare them with
Collections.synchronizedMap, and cover practical examples and common mistakes (weakly consistent iterators, non-atomic sequences of operations, etc.).