004 volatile在JSR中的定义

volatile在JSR(是Java Specification Requests的缩写,意思是Java规范提案)中的定义:

 The Java programming language allows threads to access shared variables (§17.1). As a rule, to ensure that shared variables are consistently and reliably updated, a thread should ensure that it has exclusive use of such variables by obtaining a lock that, conventionally, enforces mutual exclusion for those shared variables.

    The Java programming language provides a second mechanism, volatile fields, that is more convenient than locking for some purposes.

    A field may be declared volatile, in which case the Java Memory Model ensures that all threads see a consistent value for the variable .

    简单的翻译一下:

Java编程语言中允许线程访问共享变量。为了确保共享变量能被一致地和可靠的更新,线程必须确保它是排他性的使用此共享变量,通常都是获得对这些共享变量强制排他性的同步锁。

 Java编程语言提供了另一种机制,volatile域变量,对于某些场景的使用这要比更加的方便

 可以把变量声明为volatile,以让Java内存模型来保证所有线程都能看到这个变量的一致的一个值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值