Is this code safe? ... does it see the user in a new state?
Not especially - the fact that user is final in your code has practically no effect on thread safety, except that it cannot be replaced.
The bit that needs to change is the instance variable set by setSomething . It should be marked as volatile .
class User {
If, however (as you assume), you do not have access to the user class, you must perform synchronization, which creates a memory barrier. In its simplest form, you can combine your user access with synchronized access.
synchronized (user) { user.setSomething(something); }
Added: - It turns out (see here ) that this can be done as follows:
volatile int barrier = 0; ... user.setSomething(something);
source share