title: Java - multithreading increment
body: <p>I have the following class in my application</p>
  
  <pre><code>public class InsertErrorLinesHandler {
  
      private int currentCount;
  
      public void insertErrorLine() {
          //do something...
          currentCount++;
      }
  }
  </code></pre>
  
  <p>And I have multiple threads that are using the same instance of <code>InsertErrorLinesHandler</code>, particulary calling insertErrorLine method. After all these threads are stopped, I get the <code>currentCount</code> from this instance. </p>
  
  <p>The question is - how to rewrite this class to be sure that there won't be any concurrency problems? What I want is to be sure, that <code>currentCount</code> value will be the count of method callings from threads. Should I use static method and static variable? Make method synchronize? Make variable volatile? </p>
  
  <p>Thanks!</p>