A. Bolmarcich wrote:
On 2007-01-30, Knute Johnson <nospam@rabbitbrush.frazmtn.com> wrote:
Thank you very much for your response but it doesn't really answer my
question. As to the immutable, I'm not muting. So let me set the
scenario again.
Class with instance variable that is reference to Integer. One thread
makes new Integers and assigns them to the instance variable. The other
thread calls some method on the Integer. I want to know if making the
variable volatile will guarantee that the second thread always sees the
latest integer created by the first thread.
No, volatile does not "guarantee that the second thread always sees the
latest integer created by the first thread". What volatile guarantees
is that when one thread executes assignment statements to volatile
variables other threads will see the effect of the assignment
statements in the same order that they were executed.
It is possible that one thread starts executing an assignment statement
to a volatile variable and very slightly later another thread starts
executing a statement that uses the value of that variable. The second
thread may get the value of the variable before latest assignment
statment by the first thread. A basic problem is that without some
form of synchronization between theads (not necessarily by the Java
synchronize statement) there is no definite time ordering of operations
between threads.
answers. Can you explain what is meant in the documentation then by:
....
according to the synchronization order).