This content has been marked as final. Show 2 replies
In the circumstances when you need to, yes. However those are the circumstances in which the reference may change asynchronously. The more usual case is where you have to synchronize access to the same object, which 'volatile' can't do for you.
JavaFunda wrote:Did you read what I wrote in your [url http://forums.oracle.com/forums/message.jspa?messageID=9656148]other thread about volatile? Did you notice where I said "Every read and write of a volatile variable must go against the single copy in main memory"? Did you notice how there was some additional discussion on that page? Did you notice how primitives vs. references was not mentioned once? Don't you think that you can conclude that when Peter and I referred to "volatile variables" in that thread, that we were talking about all volatile variables?
As it is the case with primitive data types,should we declare the object refernce too as volatile to avoid the local copy?
In the future, when you have further questions on the same topic, please stick to [url http://forums.oracle.com/forums/message.jspa?messageID=9656148]the original thread.