I have good knowledge of
When a variable is defined
volatile it is read from the main memory instead of registries.
So each processor will see the same value.
In the double check the variable is defined as
volatile to be sure to check outside of
synchronized block will intercept most of cases.
If the variable is not
volatile the code will work, but if you have more processors you can go inside of the
synchronized block more than needed (also when the variable is not null).
If all access to a variable are done in the
synchronized block a
volatile is not necessary at all.