Java Concurrency Interview

Concurrent collections question 74 of 180 mid

What does Collections.unmodifiableList guarantee about thread safety?

An unmodifiable wrapper only blocks writes through that reference. The underlying list is unchanged, and if anyone retains a reference and mutates it, readers of the view see those changes with no synchronisation at all: a data race, and possibly a torn view of the internal array.

List.copyOf and List.of are different: they build a genuinely immutable list whose fields are final, which makes it safe to publish by any means, including a race. That is the final-field guarantee, and it is the reason immutability is the cheapest thread safety there is.

collections immutability

Quiz yourself on Concurrent collections Suggest a correction