Q:

do I need a lock?

MyObject myObj ...

public void updateObj(){
     MyObject newObj = getNewMyObject();
     myObj = newObj;
}

public int getSomething(){
     //O(n^2) operation performed in getSomething method
     int something = myObj.getSomething();
     return something;
}

Suppose the main thread periodically calls updateObj() and a child thread calling getSomething() method pretty often. 
Do I need a lock (or declare methods as synchronized) before myObj = newObj; and int something = myObj.getSomething(); 
Someone argued I don't need a lock here because in Java, assignment operations (e.g myObj = newObj;) is atomic. But what I don't get it is that myObj.getSomething(); this is not an atomic operation but its O(n^2) so I think a locking is still needed. Is this correct?

A:

You need to declare myObject volatile, otherwise getSomething() method may not see updated object. Other than that I cannot see any synchronization issues in the above code

