I\'m making a program in java that races a few cars against each other. Each car is a separate thread.
When cars complete the race, each one all calls this method.
++ operator is not atomic. Look at here http://madbean.com/2003/mb2003-44/.
For atomic operations you can use AtomicInteger
AtomicInteger atomicInteger = new java.util.concurrent.atomic.AtomicInteger(0)
and every time you want to increment you can call atomicInteger.incrementAndGet()
method which returns a primitive int. 0 is the default initial value for the atomic integer.