How does AtomicInteger work?
<p>I didn't think threading would be this difficult <em>sigh</em>. 
Anyways, the only way I could think of executing a function after a thread has completed is to use a static counter to increment whenever a thread ran. </p>

<pre><code>if(++threadcounter==3){doSomething(); threadcounter =0;}
</code></pre>

<p>I found this wasn't a good idea because the threadcounter at times never reaches 4.</p>

<p>So I used atomic integer</p>

<pre><code>if(atomicint.incrementAndGet()==4){doSomething(); atomicint.set(0);}
</code></pre>

<p>The counter is 5 or 0 and the app freezes. I don't know what's happening. How to use a correct counter?
 Thanks</p>

<p>EDIT:</p>
