I know increment operation is not atomic in C++ without locking. Will JVM add any lock on its implementation of iinc instruction? 解决方案 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 InterferenceYou need to either use synchronized keyword or use AtomicXXX methods for Thread safety.UPDATE: public synchronized void increment() { c++;}or AtomicInteger integer = new AtomicInteger(1);//somewhere else in codeinteger.incrementAndGet();Also read: Is iinc atomic in Java? 这篇关于iinc在Java中是原子的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-11 05:54