title: Is there a race condition in this code?
body: <p>I need to increase a counter in 5 threads until it reaches 500. Whit 5 threads like this, is working. But i need to know if it have a race condition.</p>
  
  <p>Another problem with this code is that it gives me the prints in the wrong order.</p>
  
  <pre><code>class HiloContador extends Thread {
  
      static int count = 0;
  
      @Override
      public void run() {
          for (int i = 0; i &lt; 100; i++) {
              synchronized (new Integer(count)) {
                  ++count;
                  System.out.println(count);
              }
          }
      }
  }
  </code></pre>
  
  <h2>Output</h2>
  
  <blockquote>
    <p>4
        6
        8
        9
        10
        11
        12
        5
        14
        15
        3
        17
        18</p>
  </blockquote>
  
  <p>Some ideas?</p>