JVM是否保证不缓存易失性变量? [英] Does JVM guarantee to cache not volatile variable?

查看:81
本文介绍了JVM是否保证不缓存易失性变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JVM是否保证不缓存易失性变量?

Does JVM guarantee to cache not volatile variable ?

程序员是否可以依赖JVM始终为每个线程本地缓存非易失性变量.

Can a programer depend upon on JVM to always cache non-volatile variables locally for each thread.

或者JVM可能会或可能不会这样做,因此程序员不应为此而依赖JVM.

Or JVM may or may not do this, thus a programer should not depend upon JVM for this.

非常感谢您的回答.

推荐答案

否. JVM不保证非易失性字段的缓存". JVM保证的实现是易失字段应该如何表现.字段的缓存是非标准的(未指定),并且可能因JVM的实现而异.因此,您不应该真正依赖它(即使通过某种方式发现某些数据正在被线程缓存),

No. The JVM doesn't guarantee "caching" of non-volatile fields. What implementations of JVM guarantee is how volatile fields should behave. Caching of fields is non-standard (unspecified) and can vary from JVM to JVM implementation. So, you shouldn't really rely on it (even if find out, by some way that some data is being cached by a thread)

这篇关于JVM是否保证不缓存易失性变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆