title: Thread Caching and Java Memory model
body: <p>I'm trying to understand the Java memory model and threads. As far as I understand, each thread has a local copy of the &quot;main&quot; memory. So if one thread tries to change an <code>int</code> variable, for example, of some object, it caches the <code>int</code> variable and if it changes it, other thread might not see the change.</p>
  <p>But what if threads cache some object instead of int? What threads cache it in this case? If a thread caches a reference to an object any change to the state of the object are not visible to other threads? Why?</p>