title: Memory Consistency - happens-before relationship in Java
body: <p>While reading Java docs on Memory Consistency errors. I find points related to two actions that creates happen - before relationship:</p>
  
  <ul>
  <li><p>When a statement invokes <code>Thread.start()</code>, every statement that has a
  happens-before relationship with that statement also has a
  happens-before relationship with every statement executed by the new
  thread. The effects of the code that led up to the creation of the
  new thread are visible to the new thread.</p></li>
  <li><p>When a thread terminates and causes a <code>Thread.join()</code> in another thread
  to return, then all the statements executed by the terminated<br>
  thread have a happens-before relationship with all the statements<br>
  following the successful join. The effects of the code in the thread 
  are now visible to the thread that performed the join.</p></li>
  </ul>
  
  <p>I am not able to understand their meaning. It would be great if someone explain it with a simple example.</p>