Quick revision
The short answer
Properly constructed immutable objects are thread-safe because their state never changes after construction, so there is no write that could race with a read. The Java Memory Model adds a specific guarantee for final fields: a thread that obtains a reference to an object after its constructor finishes sees the values of its final fields, and of everything reachable through them, as they were at the end of construction, even if the reference was published through a data race. The guarantee breaks if this escapes during construction, for example by registering a listener in the constructor, and it is only shallow: final fields that point to mutable objects do not stop those objects from changing later.
What to remember
In this answer, we saw that immutable objects are thread-safe because there are no writes after construction and therefore nothing to race on, and because the Java Memory Model freezes final fields at the end of the constructor: any thread that obtains the reference afterwards sees those fields, and what they reference, as of construction, even if the publication itself was a data race. The guarantee is broken when this escapes during construction, for example by registering a listener in the constructor, and it is only shallow, so final fields pointing to mutable objects still need defensive copies.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Properly constructed immutable objects are thread-safe because their state never changes after construction, so there is no write that could race with a read. The Java Memory Model adds a specific guarantee for final fields: a thread that obtains a reference to an object after its constructor finishes sees the values of its final fields, and of everything reachable through them, as they were at the end of construction, even if the reference was published through a data race. The guarantee breaks if this escapes during construction, for example by registering a listener in the constructor, and it is only shallow: final fields that point to mutable objects do not stop those objects from changing later.
Why this question is asked
We often say immutable objects are thread-safe and move on, but the statement hides two separate facts: one about logic, nothing changes so nothing can race, and one about visibility, another thread must actually see the values the constructor wrote. The second is not obvious at all, because the JVM and the CPU are allowed to reorder writes. Interviewers ask this at the ten-year level to see whether we know what the Java Memory Model promises and what it does not. In this answer, we will recap data races and visibility, show how a non-final object can be seen half-built, explain the final field guarantee, and then break it in the two ways the question asks about.
1A Quick Recap: Data Races and Visibility
The Java Memory Model, the JMM, is the part of the language specification that says which values a read of a shared variable may return when several threads are involved. Without synchronisation, it allows surprising results, because compilers and CPUs reorder instructions and cache values for speed, as long as a single thread cannot tell the difference.
A data race happens when one thread writes a variable and another reads it without a happens-before relationship between them. Happens-before is the JMM's ordering rule; it is established by things like releasing and acquiring the same lock, writing and then reading a volatile variable, or starting a thread. Without it, the reader may see an old value, or see writes in a different order from the one the writer performed.
2How a Non-Final Object Can Be Seen Half-Built
Here is the classic example. One thread creates a Point and stores it in a plain static field; another thread reads the field. The Point's fields are not final.
Creating the object involves allocating memory with default values, writing x and y in the constructor, and writing the reference into shared. Nothing forces thread B to see those writes in that order. The JMM permits B to see the reference before the field writes, so it can print 0,0 for an object whose constructor clearly set 3 and 4. On x86 processors this is rare in practice, but it can be observed on ARM, and the JIT compiler may also reorder the stores. Code that depends on not seeing it is broken by the language rules, regardless of hardware.
3What the Final Field Guarantee Says
Now make the fields final. The JMM gives final fields a special rule, specified in section 17.5 of the Java Language Specification. At the end of the constructor there is a conceptual freeze of the final fields. Any thread that obtains a reference to the object after that freeze, by any means, is guaranteed to see the final fields with the values they had at the freeze. The guarantee extends to objects reached through those final fields: if a final field refers to an array or a list that the constructor filled, a reader sees the array or list as it was when the constructor finished.
8 messages in order. Play them, or step through them one at a time.
The race may delay seeing the reference, never the frozen final fields.
Notice that the publication is still a data race. Thread B may see null and skip the print, because nothing guarantees when B sees the new reference. But if it sees the reference at all, it sees x and y correctly. That is the remarkable part: immutable objects with final fields are safe even when shared carelessly, which is why String, Integer and the java.time classes can be passed between threads without any synchronisation. Combined with the fact that nothing is ever written after construction, this makes immutable objects fully thread-safe for readers.
4Breaking It 1: Letting this Escape the Constructor
The guarantee applies to threads that obtain the reference after the constructor finishes. If the constructor itself hands out this, the reference to the object under construction, another thread can get it before the freeze, and then none of the final field promises apply.
The feed's thread can call onPrice before the constructor has assigned the fields, and it sees null even though both fields are final. Moving the register call to the last line of the constructor is not a fix either, because the freeze happens when the constructor returns, so the reference was still published before it. The safe pattern is to construct first and register afterwards, for example through a static factory method that creates the watcher and then calls feed.register(watcher). Starting a thread in a constructor, or passing this to any other object there, has the same problem.
5Breaking It 2: Shallow Immutability
The second way is subtler. Final freezes the field, and the guarantee covers the state of referenced objects as of the end of construction, but it says nothing about later changes to those objects.
The field members is final, but the ArrayList it points to is mutable and is still reachable by the caller. Later writes to it are ordinary data races: readers may see the old size, the new element without the new size, or a corrupted internal array during a resize. So a class with final fields is only truly immutable, and only thread-safe, when everything reachable from those fields is itself immutable or never changed after construction. The fix is the usual defensive copy into an unmodifiable list, List.copyOf(members), made in the constructor so the copy is part of the frozen state.
6Follow-up questions
Is volatile needed to publish an immutable object?
Not for correctness of the object's contents; the final field rule covers that. But without volatile or another happens-before edge, other threads may keep seeing the old reference, or null, for an unbounded time. So we still publish through a volatile field, a concurrent collection or a lock when we need other threads to see the new object promptly.
Do records get the final field guarantee?
Yes. A record's fields are private and final, so they are frozen at the end of the canonical constructor. Like any class, a record with a mutable component such as an ArrayList is only shallowly immutable unless its compact constructor copies that component into an unmodifiable one.
Can reflection or deserialisation break final fields?
Reflection with setAccessible can change final instance fields in ordinary classes, and the JMM gives weaker guarantees for such changes; record fields and static finals cannot be changed this way. Java serialisation sets final fields through internal mechanisms after construction, which is one reason immutable classes often use a serialisation proxy or validate in readResolve.
7Conclusion
In this answer, we saw that immutable objects are thread-safe because there are no writes after construction and therefore nothing to race on, and because the Java Memory Model freezes final fields at the end of the constructor: any thread that obtains the reference afterwards sees those fields, and what they reference, as of construction, even if the publication itself was a data race. The guarantee is broken when this escapes during construction, for example by registering a listener in the constructor, and it is only shallow, so final fields pointing to mutable objects still need defensive copies.
Open with
There are two reasons. First, logically, an immutable object's state never changes after construction, so there are no write-read races to protect against. Second, visibility: without synchronisation the JMM normally lets another thread see a reference to an object before the constructor's writes, so with plain fields a reader could see zeros in an object that was constructed with 3 and 4.
Then, if they want more
Final fields have a special rule in the JLS. At the end of the constructor the final fields are frozen, and any thread that gets the reference after that, by any means, even through a data race, is guaranteed to see the final fields, and everything reachable through them, as they were at the end of construction.
That is why String or Instant can be shared without locks. The race still means a reader might not see the new reference promptly, so I still publish through something like a volatile field when timeliness matters. The guarantee breaks in two ways.
If this escapes in the constructor, for example registering this as a listener or starting a thread there, another thread can call into the object before the freeze and see nulls even in final fields; the fix is to register from a factory method after construction.
And it is shallow: a final field pointing to a mutable ArrayList that someone changes later is a normal data race, so I copy into an unmodifiable list in the constructor.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why are properly constructed immutable objects thread-safe without synchronisation? What...": https://scrivio-interview-library.netlify.app/java/concurrency-patterns/4cb1c1af9c/