using volatile keyword in java4 and java5
java
Solution
People have provided good points and references responding to my question answering first part.
Going specific to the second part of question, this i read at some forum:
A volatile declared long is atomic (pre-Java 5 also) in the sense that it guarantees (for all JVM implementations) a read or write go directly to main memory instead of two 32-bit registers.
And
Pre-Java 5, volatile was supposed to provide such guarantees for long and double. However things did not work out this way in practice, and implementations frequently violated this guarantee. As I recall the issue seemed to get fixed around JDK 1.4, but as they were still working on the whole memory model thing, they didn't really make any clear announcements about it until JDK 5, when the new rules were announced, and memory guarantees actually meant something.
And this is from Java Language Specification,Second Edition:
17.4 Nonatomic Treatment of double and long
The load, store, read, and write actions on volatile variables are atomic, even if the type of the variable is double or long.
Problem
what is the difference in using `volatile keyword` in java4 and java5 onwards? and related to that, Read/write operations on non-atomic variables(long/double) are atomic when they are declared as volatile. Is this also true for java4 or it is valid from java5 onwards???