I've recently stumbled upon an article titled Synchronize access to mutable fields. It claims that:
For example, in a multi-threaded environment, all
getandsetmethods for mutable fields should usually besynchronizedmethods. This includes primitive fields.
My question is why? What would be the use of synchronizing getId method? Or what could happen if I don't synchronize it.
For example I pass a UserContext to a Spring Service function and call getUserId within the function. Could this be a problem if getUserId is not synchronized?
 
     
     
    