当前位置: 技术问答>java相关
volatile的使用
来源: 互联网 发布时间:2017-03-17
本文导语: 在有关线程的学习中发现在其变量声明中, private volatile int value; 请问 该关键字的意义是什么? | The volatile keyword is used as a modifier on member variables to force individual threads to rere...
在有关线程的学习中发现在其变量声明中,
private volatile int value;
请问 该关键字的意义是什么?
private volatile int value;
请问 该关键字的意义是什么?
|
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. Chances are that most of you expected this behavior from the Java VM already. In fact, many experienced Java developers don’t understand when the use of volatile is necessary.
The volatile keyword is used to tell the VM that it should not keep a private copy of a variable and should instead interact directly with the shared copy.
The volatile keyword is used to tell the VM that it should not keep a private copy of a variable and should instead interact directly with the shared copy.
|
static int ABSTRACT
The int value representing the abstract modifier.
static int FINAL
The int value representing the final modifier.
static int INTERFACE
The int value representing the interface modifier.
static int NATIVE
The int value representing the native modifier.
static int PRIVATE
The int value representing the private modifier.
static int PROTECTED
The int value representing the protected modifier.
static int PUBLIC
The int value representing the public modifier.
static int STATIC
The int value representing the static modifier.
static int STRICT
The int value representing the strictfp modifier.
static int SYNCHRONIZED
The int value representing the synchronized modifier.
static int TRANSIENT
The int value representing the transient modifier.
static int VOLATILE
The int value representing the volatile modifier
The int value representing the abstract modifier.
static int FINAL
The int value representing the final modifier.
static int INTERFACE
The int value representing the interface modifier.
static int NATIVE
The int value representing the native modifier.
static int PRIVATE
The int value representing the private modifier.
static int PROTECTED
The int value representing the protected modifier.
static int PUBLIC
The int value representing the public modifier.
static int STATIC
The int value representing the static modifier.
static int STRICT
The int value representing the strictfp modifier.
static int SYNCHRONIZED
The int value representing the synchronized modifier.
static int TRANSIENT
The int value representing the transient modifier.
static int VOLATILE
The int value representing the volatile modifier