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.
from java thread programming
本文详细介绍了Java中volatile关键字的作用及使用方式。它强制每个线程在每次访问变量时都从共享内存中重新读取变量值,并立即把修改后的值写回共享内存,确保了多线程环境下的数据一致性。
1128

被折叠的 条评论
为什么被折叠?



