2 Replies Latest reply: Jun 16, 2011 10:42 AM by 796440 RSS

    Object reference with volatile modifier?

    866541
      As it is the case with primitive data types,should we declare the object refernce too as volatile to avoid the local copy?
        • 1. Re: Object reference with volatile modifier?
          EJP
          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.
          • 2. Re: Object reference with volatile modifier?
            796440
            JavaFunda wrote:
            As it is the case with primitive data types,should we declare the object refernce too as volatile to avoid the local copy?
            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?

            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.