Is iinc atomic in Java?
问题 I know increment operation is not atomic in C++ without locking. Will JVM add any lock on its implementation of iinc instruction? 回答1: No its not Retrieve the current value of c. Increment the retrieved value by 1. Store the incremented value back in c. Java Documentation for Atomicity and Thread Interference You need to either use synchronized keyword or use AtomicXXX methods for Thread safety. UPDATE : public synchronized void increment() { c++; } or AtomicInteger integer = new