Java Concurrency Interview

The Java memory model question 17 of 180 senior

What is safe publication, and which ways of achieving it can you name?

Publishing an object means making a reference reachable by another thread. Unsafely published, the reader may see the reference before the fields, and observe a half-built object even though the code never mutates it after construction.

The safe ways, all of which come down to a happens-before edge between the construction and the read:

An immutable object with all-final fields is the exception that needs none of this: the final-field guarantee makes it safe to share by any means, including a data race.

memory-model publication

Quiz yourself on The Java memory model Suggest a correction