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

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

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -