The use of the volatile keyword allows method one and method two to be executed concurrently, but guarantees that accesses to the shared value for i and j occur exactly as many times, and in exactly the same order, as they appear to occur during execution of the program text be each thread.
Therefore, method two never observes a value for j greater than that for i, because each update to i must be reflected in the shared value for i before the update to j occurs.
It is possible, however, that any given invocation of method two might observe a value for j that is much greater than the value observed for i, because method one might be executed many times between the moment when method two fetches the value of i and the moment when method two fetches the value of j.
more here hhmm... I am not sure about the second paragraphe...I would have tought it is the other way around, that method two never observes a value for *i* greater than that for *j*...but this example comes from ibm's web site and they are probably right...ok, can anyone confirm all this?
[ January 07, 2003: Message edited by: Daniela Ch ]