Can AtomicInteger replace synchronized?
<p>The javadoc for the java.util.concurrent.atomic package says the following:</p>

<blockquote>
  <p>A small toolkit of classes that
  support lock-free thread-safe
  programming on single variables.</p>
</blockquote>

<p>But I don't see any thread-safe (synchronized or Lock) code inside any of the AtomicInteger or AtomicBoolean classes.</p>

<p>So, are these 2 the same:<p>
1. </p>

<pre><code>int i;
synchronized(this){i++;}
</code></pre>

<p>2.</p>

<pre><code>AtomicInteger i = new AtomicInteger();
i.getAndIncrement();
</code></pre>

<p><strong>Update</strong>: Thanks for the answers. Is volatile needed when I use AtomicInteger?</p>
