First the quote from From JLS 8 Sec 17.7
Writes to and reads of references are always atomic, regardless of whether they are implemented as 32-bit or 64-bit values.
Here is the scenario that confuses me, given Employee class and a method within this class called calculate which returns a reference to an instance of Employee.
Employee emp = calculate();
When a write to variable is atomic, it means that no other thread can access that variable until the atomic operation is done, and in the given assignment example, does the atomicity of the write include the evaluation of the right side of the assignment (however complex), OR does the atomicity of the write only apply to when the right side is fully evaluated, and then the write operation is actually done.
In other words, I'm asking if during the evaluation of calculate()
, the access to the emp
variable is denied for other threads, or is it denied only when the right side of the assignment is fully evaluated and the write operation to emp
start?
Sorry for the long story, and Thanks a lot!