title: Java multi-threading & Safe Publication
body: <p>After reading &quot;<a href="http://jcip.net/" rel="noreferrer">Java concurrent in practice</a>&quot; and &quot;<a href="http://neilbartlett.name/blog/osgibook/" rel="noreferrer">OSGI in practice</a>&quot; I found a specific subject very interesting; Safe Publication. The following is from JCIP:</p>
  <blockquote>
  <p>To publish an object safely, both the reference to the object and the object's state must be made visible to other threads at the same time. A properly constructed object can be safely published by:</p>
  <ul>
  <li>Initializing an object reference from a <em>static</em> initializer.</li>
  <li>Storing a reference to it into a <em>volatile</em> field.</li>
  <li>Storing a reference to it into a <em>final</em> field.</li>
  <li>Storing a reference to it into a field that is properly guarded by a (<em>synchronized</em>) lock.</li>
  </ul>
  </blockquote>
  <p>My first question: how many java developers are aware of this (problem)?
  How many real world java applications are really following this, AND is this really a real problem? I have a feeling that 99% of the implemented JVMs out there are not that &quot;evil&quot;, i.e. a thread is not guaranteed (in fact its practical (almost) &quot;impossible&quot;) to see stale data just because the reference is not following the &quot;safe publication idiom&quot; above.</p>