title: Multi-thread state visibility in Java: is there a way to turn the JVM into the worst case scenario?
body: <p>Suppose our code has 2 threads (A and B) have a reference to the same instance of this class somewhere:</p>
  
  <pre><code>public class MyValueHolder {
  
      private int value = 1;
  
      // ... getter and setter
  
  }
  </code></pre>
  
  <p>When Thread A does <code>myValueHolder.setValue(7)</code>, there is no guarantee that Thread B will ever read that value: <code>myValueHolder.getValue()</code> could - in theory - keep returning <code>1</code> forever.</p>
  
  <p>In practice however, the hardware will clear the second level cache sooner or later, so Thread B will read <code>7</code> sooner or later (usually sooner).</p>
  
  <p><strong>Is there any way to make the JVM emulate that worst case scenario for which it keeps returning <code>1</code> forever for Thread B?</strong> That would be very useful to test our multi-threaded code with our existing tests under those circumstances.</p>