title: Are accumulators thread-safe?
body: <p>I'm using accumulators and wanted to know if these objects are thread-safe?</p>
  
  <p><code>accumInt</code> is a type of <code>AccumulatorParam&lt;Integer&gt;</code>.</p>
  
  <pre><code>// Current value accumInt -&gt; 6
  AccumulatorThread t1 = new AccumulatorThread();
  t1.setAccum(accumInt); 
  t1.setValueToAdd(5);
  
  AccumulatorThread t2 = new AccumulatorThread();
  t2.setAccum(accumInt);
  t2.setValueToAdd(7);
  
  new Thread(t1).start();
  new Thread(t2).start();
  
  System.out.println(accumInt.value()); // 11 or 13 or 18
  </code></pre>
  
  <p><code>AccumlatorThread</code> class:</p>
  
  <pre><code>class AccumulatorThread implements Runnable {
      Accumulator&lt;Integer&gt; accum;
      Integer              valueToAdd;
  
      public Integer getValueToAdd() {
          return valueToAdd;
      }
  
  
      public void setValueToAdd(Integer valueToAdd) {
          this.valueToAdd = valueToAdd;
      }
  
      public Accumulator&lt;Integer&gt; getAccum() {
          return accum;
      }
  
  
      public void setAccum(Accumulator&lt;Integer&gt; accum) {
          this.accum = accum;
      }
  
      public void run() {
          System.out.println("Value to Add in Thread : "+valueToAdd);
          accum.add(valueToAdd);
      }
  }
  </code></pre>
  
  <p>The behavior shows that it is not a thread safe. Am I missing something?</p>