title: Java Atomicity & a good Compare and Swap framework?
body: <p>Do you guys think this is a good generic framework for atomic operations?
  Also do you think its correct to say With respect to Java applicatitions individual byte codes are atomic as there is no way of executing more than one byte code at a time with a single JVM? So if there was a single byte code for if else, then this if else instruction would be atomic?</p>
  
  <pre><code>// CAS, Compare and Swap
  public abstract class CASOperation&lt;T&gt; {
  
  protected T valueAtStart;
  
  public CASOperation(){
      valueAtStart = objectToReview();
  }
  
  public void exec(){
      synchronized(this){
          while(!valueAtStartEqualsTheCurrent()){
              valueAtStart = objectToReview();
          }
          execImp();
      }
  }
  
  private boolean valueAtStartEqualsTheCurrent() {
      if (objectToReview().equals(valueAtStart)){
          return true;
      } else {
          return false;
      }
  }
  
  abstract protected T objectToReview();
  
  abstract protected void execImp();
  </code></pre>
  
  <hr>
  
  <p>Its meant to be a compare and execute framework really, so after checking that the original snapped value hasn't changed then we execute some block of code.</p>