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

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -