title: Is AtomicInteger.incrementAndGet thread safe?
body: <p>For example, if I run this code from multiple threads and each thread for many times, will there be potentially a data race?</p>
  
  <pre><code>   public boolean swap(int i, int j) {
      if (value.get(i) &lt;= 0 || value.get(j) &gt;= maxval) {
          return false;
      }
      value.decrementAndGet(i);
      value.incrementAndGet(j);
      return true;
  }
  </code></pre>
  
  <p>BTW, is there any difference if I use decrementAndGet or getAndDecrement here? </p>
  
  <p>value here is an AtomicIntegerArray. I need to do performance test among different synchronization method. So I swap elemtents in value and see if the output sum the same to what is expected</p>
  
  <p>My task is to find a method that "should not be DRF," but "must still be deadlock-free", and is also much faster than ReentrantLock. So I'm troubling with finding a method that has data race...</p>