Java concurrency: is final field (initialized in constructor) thread-safe?

As already pointed out it’s absolutely thread-safe, and final is important here due to its memory visibility effects. Presence of final guarantees that other threads would see values in the map after constructor finished without any external synchronization. Without final it cannot be guaranteed in all cases, and you would need to use safe publication … Read more

What does “volatile” mean in Java?

Short of reading the memory model specification, I recommend you read http://jeremymanson.blogspot.com/2008/11/what-volatile-means-in-java.html. It’s written by one of the JMM authors and should answer your question. Thinking of memory reads and writes in terms of the happens-before clause is also helpful; the JMM for Java 5 onwards adds happens-before semantics to volatile. Specifically, when you read … Read more

Must all properties of an immutable object be final?

The main difference between an immutable object (all properties final) and an effectively immutable object (properties aren’t final but can’t be changed) is safe publication. You can safely publish an immutable object in a multi threaded context without having to worry about adding synchronization, thanks to the guarantees provided by the Java Memory Model for … Read more