title: executing block of code atomically
body: <p>How would you answer the following question?</p>
  
  <blockquote>
    <p>A method of a java class contains a block of code that must be
    executed atomically. Explain, using appropriate pseudo-code, how you
    would ensure that this block of code is executed atomically</p>
  </blockquote>
  
  <p>Would I achieve this by making the method ..</p>
  
  <pre><code>public final AtomicInteger x = new AtomicInteger(0);
  </code></pre>
  
  <p>then ensuring the get statement returned:</p>
  
  <pre><code>x.get()
  </code></pre>
  
  <p>and if I wanted to increment the value of x would I do this?</p>
  
  <pre><code>x.getAndIncrement();
  </code></pre>