当前位置:网站首页>See how much volatile you know

See how much volatile you know

2022-06-22 09:13:00 C_ x_ three hundred and thirty

For the sake of running speed ,java The compiler will put frequently accessed variables into the cache ( Strictly speaking, it should be working memory ) in , Read variables are read from the cache . But in multithreaded programming , There may be inconsistencies between the values in memory and the values in the cache .volatile Used to limit that variables can only be read from memory , Ensure that for all threads , The values are consistent . however volatile Atomicity is not guaranteed , You can't guarantee thread safety

原网站

版权声明
本文为[C_ x_ three hundred and thirty]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220910015572.html