title: Is the += operator thread-safe in Java?
body: <p>I found the following Java code.</p>
  
  <pre><code>for (int type = 0; type &lt; typeCount; type++)
      synchronized(result) {
          result[type] += parts[type];
      }
  }
  </code></pre>
  
  <p>where <code>result</code> and <code>parts</code> are <code>double[]</code>.</p>
  
  <p>I know basic operations on primitive types are thread-safe, but I am not sure about <code>+=</code>. If the above <code>synchronized</code> is necessary, is there maybe a better class to handle such operation?</p>