最近看Java多线程有关知识,根据JMM的相关介绍,线程会将共享的对象从主内存拷贝一份到工作线程中,如果不考虑同步的话,会有不可见的问题,如果加了volatile后就会保证内存可见性。那么对于volatile型的共享对象,是否会拷贝到工作线程中呢
------解决思路----------------------
The volatile keyword is used as a modifier on member variables to force individual
threads to reread the variable’s value from shared memory every time the variable is
accessed. In addition, individual threads are forced to write changes back to shared
memory as soon as they occur. This way, two different threads always see the same
value for a member variable at any particular time.