I know increment operation is not atomic in C++ without locking.
Will JVM add any lock on its implementation of iinc
instruction?
i++ is not atomic in java.
It is better to use
AtomicInteger atomic= new AtomicInteger(1);
There are methods defined like
atomic.getAndDecrement();
atomic.getAndIncrement();
atomic.decrementAndGet();
atomic.incrementAndGet();
any operation with above method would be atomic.
This class comes under java.util.concurrent.atomic
package.
Java 1.5
has added many features for thready safety and thread concurrency.