Quick revision
The short answer
Immutable objects are thread-safe because their state never changes after construction, so there is nothing for threads to race on. The Java Memory Model adds a guarantee for final fields: once the constructor finishes, any thread that sees a reference to the object sees the final fields as the constructor set them, plus the objects reachable through them as of that moment, even without synchronisation. That guarantee fails if this escapes during construction, does not cover later changes to objects reachable through a final field, and does not apply to non-final fields, which need safe publication.
What to remember
In this answer, we saw that immutable objects are thread-safe because their state never changes, so no thread can race on it, and that the JMM backs this with the final field rule: once the constructor finishes, every thread that sees the object sees its final fields, and what they referred to at that moment, as the constructor left them, even without synchronisation. The rule breaks if this escapes during construction, it does not cover later changes to objects reachable through final fields, and it does not apply to non-final fields, which need safe publication through volatile, locks, static initialisers or concurrent collections.
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.
Immutable objects are thread-safe because their state never changes after construction, so there is nothing for threads to race on. The Java Memory Model adds a guarantee for final fields: once the constructor finishes, any thread that sees a reference to the object sees the final fields as the constructor set them, plus the objects reachable through them as of that moment, even without synchronisation. That guarantee fails if this escapes during construction, does not cover later changes to objects reachable through a final field, and does not apply to non-final fields, which need safe publication.
Why this question is asked
Threads in Java can see each other's writes late, out of order or not at all unless the program creates the right ordering. That is why a value written by one thread may look wrong in another, even on a single object. Immutable objects avoid most of this, but the reason they are safe is a specific rule of the memory model, with specific limits. Interviewers ask about it at this level to see whether we know the rule precisely enough to spot the cases where it breaks. In this answer, we will recap the visibility problem, explain the final field guarantee, break it by letting this escape, look at what it does and does not cover, and see what safe publication means for everything else.
1A Quick Recap: Why Threads Can See Stale Values
The Java Memory Model, or JMM, is the part of the language specification that says which writes one thread is guaranteed to see from another. Without a guarantee, the compiler, the JIT and the CPU are allowed to reorder and cache memory operations for speed. So if thread A creates an object and stores a reference in a shared field, thread B may see the reference before it sees the values the constructor wrote into the object's fields.
Normally we create the ordering we need with a happens-before relationship: unlocking a lock happens-before a later lock of the same lock, a write to a volatile field happens-before a later read of it, and so on. Code that shares objects without any such relationship has a data race.
Printing 0 is rare on x86 hardware, but the JMM allows it, and it can happen on weaker processors such as ARM or after JIT reordering. Code that relies on luck here is broken.
2The Final Field Guarantee
The JMM has a special rule for final fields (JLS section 17.5). At the end of a constructor, there is a conceptual freeze of the object's final fields. Any thread that obtains a reference to the object after that, through any route, even a data race like the one above, is guaranteed to see the final fields with the values the constructor assigned. The only condition is that the object was properly constructed, which means this did not escape before the constructor finished.
6 messages in order. Play them, or step through them one at a time.
Any thread that sees the reference after the freeze sees the final values, even through a data race.
This is why immutable objects are safe to share. Their state is set once, in the constructor, in final fields, and never changes. No thread can see a partly built state, and since there are no later writes, there is nothing to race on afterwards. String depends on exactly this guarantee, which is why a String passed between threads through a plain field still has its characters.
3Breaking the Guarantee: Letting this Escape
The freeze happens at the end of the constructor, so the guarantee only protects threads that see the reference after that point. If the constructor gives this to another thread before finishing, that thread can see the final fields before they are set, and the JMM promises nothing.
Other ways this escapes are starting a thread in the constructor that uses this, passing this to a static registry, or creating an inner class or lambda instance that captures this and handing it to other code. The fix is always the same: complete construction first, then publish, typically from a static factory method.
4What the Guarantee Covers and What It Does Not
The guarantee extends past the field itself. If a final field refers to an object, such as an array or a list, other threads see that object and everything reachable from it at least as up to date as it was at the end of the constructor. So an immutable class that fills an ArrayList in its constructor, stores it in a final field and never changes it again is safe to share.
But the guarantee is a snapshot of the moment of the freeze. If anyone changes the reachable object later, through a getter that exposed it or through the caller's reference, those changes have no special visibility at all. Other threads may or may not see them, in any order. That is one more reason to copy mutable inputs and never expose internal objects.
And the guarantee applies only to final fields. A non-final field in the same object, even one assigned in the constructor, has no such promise. That is why an object that is effectively immutable, never changed after construction but without final fields, is only safe if it is published safely.
| Situation | Guaranteed? |
|---|---|
| final field set in constructor, no escape | yes, even through a data race |
| object reachable through a final field, as of constructor end | yes |
| later change to that reachable object | no |
| non-final field set in constructor | no, unless safely published |
| final field when this escaped during construction | no |
5Safe Publication for Everything Else
Safe publication means making an object visible to other threads in a way that creates a happens-before relationship between the constructor and the readers. Then all fields written before publication, final or not, are visible. The common ways are: initialising the reference in a static initialiser, storing it in a volatile field or an AtomicReference, storing it in a final field of another properly constructed object, storing it in a field guarded by a lock that readers also take, or putting it into a thread-safe collection such as ConcurrentHashMap or a BlockingQueue.
For immutable objects with final fields, safe publication is not needed for the object's own state, but it is still needed for the reference itself if readers must see the newest object rather than an older one. In practice we usually publish immutable snapshots through a volatile field or AtomicReference anyway, which gives both.
6Follow-up questions
What is safe publication?
It is any way of handing an object to other threads that guarantees they see it fully constructed. The JDK gives us several: a static initialiser, a volatile or AtomicReference field, a final field of a properly constructed object, a field protected by a lock that both sides use, and the thread-safe collections in java.util.concurrent. Each creates a happens-before edge from the writes in the constructor to the reads in other threads.
Is volatile needed on a field that holds an immutable object?
Not for the object's contents, which the final field rule protects. It is needed if readers must reliably see a new object after a writer replaces the old one. Without volatile, a reader might keep seeing the old reference indefinitely, for example inside a loop the JIT has optimised.
Does the final field guarantee hold for fields changed by reflection after construction?
No. Changing a final field with reflection after construction has no defined visibility for other threads, and the JIT may have already treated the value as constant. Since recent JDKs, changing final fields through reflection is being restricted further, so check your version; it should not be used in normal code.
7Conclusion
In this answer, we saw that immutable objects are thread-safe because their state never changes, so no thread can race on it, and that the JMM backs this with the final field rule: once the constructor finishes, every thread that sees the object sees its final fields, and what they referred to at that moment, as the constructor left them, even without synchronisation. The rule breaks if this escapes during construction, it does not cover later changes to objects reachable through final fields, and it does not apply to non-final fields, which need safe publication through volatile, locks, static initialisers or concurrent collections.
Open with
Immutable objects are thread-safe because there are no writes after construction, so there is nothing to race on, and the memory model makes sure the construction itself is seen correctly.
Then, if they want more
Normally, if one thread publishes an object through a plain field, another thread could see the reference before the field values, so it might read zero or null.
For final fields, JLS 17.5 gives a special guarantee: at the end of the constructor the final fields are frozen, and any thread that later sees the reference, even through a data race, sees those final values.
It also covers objects reachable through the final field as they were at the end of the constructor, so an array filled in the constructor and never changed is visible correctly. There are three limits.
First, the object must be properly constructed: if this escapes during construction, for example by registering a listener or starting a thread in the constructor, another thread can see the final fields before they are set. The fix is to publish from a static factory after construction. Second, later changes to a reachable mutable object are not covered at all.
Third, non-final fields get no guarantee, so an effectively immutable object without final fields must be safely published, through a volatile or AtomicReference, a static initialiser, a lock, or a concurrent collection.
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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 immutable objects thread-safe, and what does the Java Memory Model guarantee...": https://scrivio-interview-library.netlify.app/java/immutability/fbcd7007d0/