Wiki Markup |
---|
According to the Java Language Specification \[[JLS 05|AA. Java References#JLS 05]\], section, 8.3.1.4 {{volatile}} Fields: |
A field may be declared
volatile
, in which case the Java memory model (§17) ensures that all threads see a consistent value for the variable.
...
This noncompliant code example shows an array that is declared volatile
. It appears that, when a value is written by a thread to one of the array elements, it will be visible to other threads immediately. This is counter-intuitive as misleading because the volatile
keyword just makes the array reference visible to all threads and does not affect the actual data contained within the array.
...
Code Block | ||
---|---|---|
| ||
class Safe { AtomicIntegerArray airaia = new AtomicIntegerArray(5); // other code } airaia.set(1, 10); |
Risk Assessment
...