The answer implied that the only reason for using synchronize(this) was for the case when the this reference escaped from the constructor.
But this reasoning is wrong. I added another answer to this question: stack overflow
You showed a case where at first glance, using synchronized(this) in the constructor is reasonable, because it really ensures that getM() will have the correct value for the instance variable m when called from another thread.
And if you didn’t have these synchronized blocks, it would not be necessary - it is possible for another thread to see the null value for the field m even after the constructor completes, because it didn’t happen - until the relationship between assigning m in the constructor in the same thread and reading m in the getM method in another thread.
But : how did you transfer the Ideone instance from one thread to another thread? If you did this in a field without any synchronization mechanism, so without any action - before the relationship, then the second thread does not guarantee that the entire instance of Ideone completely absent.
If it sees an instance, then the data in the instance, if they are true, but in this case can also see null .
However, if you used a synchronization mechanism to transfer an instance of Ideone , then this mechanism already created a connection between events and then, and using synchronized in the constructor and getM not necessary anymore.
And since all the safe mechanisms for transferring objects between threads are connected with the synchronization mechanism, which establishes a connection between events, then (almost) you never need to do what you do with synchronized in the constructor.
Erwin bolwidt
source share