java - Does volatile mean it is thread safe -
java - Does volatile mean it is thread safe -
in java, when want ensure compiler should not optimization keeping local re-create of variable, create variable volatile. using variable volatile ensures threads not utilize local re-create of variable utilize variable stored in main memory. but, mean volatile variable thread-safe? how differ in case of primitive type , in case utilize user defined object?
volatile
means value fresh; if thread set new object variable before you, see object.
it not alter behavior of value; cannot magically create object thread-safe.
java thread-safety compiler-optimization
Comments
Post a Comment