Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:34:24+00:00 2026-06-13T07:34:24+00:00

JMM (Java Memory Model) is free to reorder statements. Of course, this is especially

  • 0

JMM (Java Memory Model) is free to reorder statements.

Of course, this is especially tricky when dealing with multithreading environment.

JMM rules precised that volatile and final variables are always fully initialized before constructor finishes and if and only if reference hasn’t “escape” from within constructor.

It implies that “normal” variables (non-final and non-volatile) aren’t expected to be seen up-to-date by any concurrent threads.

My question might seem stupid at first glance, but it really doesn’t:

Are any object’s references set AFTER constructor completes (completes not meaning with initialization of all variables already made, but simply reaching the end of the ‘constructor’ process)? Is there a rule in any JSR asserting it?
Or might it exist an exceptional case where any reference could be sent back to client BEFORE constructor completes?

Indeed, if statements reordering is reputed so free, it may also imply the sending of the object’s reference ‘happens-before’ constructor completes. So, we’d come across the same case of the “this escape” to avoid.

To put it in a nutshell, is reference ALWAYS be sent after constructor completes?

After searching into the JLS: the only place where returning of object’s reference is related is: (excerpt of JSR-12.5)

Just before a reference to the newly created object is returned as the
result, the indicated constructor is processed to initialize the new
object using the following procedure:

No relation to JMM … therefore it can be ensured that constructor completion always happens-before passing reference whatever the case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:34:25+00:00Added an answer on June 13, 2026 at 7:34 am

    Within the context of a thread the reference will be set. However, the JMM allows shared variables to be set in one thread and not yet synchronised to the other thread.

    Volatile and final guarantee this by guaranteeing inter-thread synchronisation of reads and writes to the variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it is mentioned in the Java Memory Model that: When a thread exits a
I have a question regarding the Java Memory Model. Here is a simple class
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
Given the J5+ memory model (JSR-133) is the following code thread-safe and permissible? And
Can you help me clarify the usages of the float primitive in Java? My
Question concerning the JMM and the semantics concerning volatile fields that are written to
After a lot of research I believe I understand the JMM quite well, certainly
I just want to check if my understanding of the JMM's thread start synchronization
Can anyone tell me whether this class is threadsafe or not ? class Foo
Assuming this class: public class AmIThreadSafe { private int a; private int b; AmIThreadSafe(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.