Java int concurrency int is equivalent to atomicinteger incrementAndGet()?

Are these two equivalent? In other words, is the and - Operator atomic?

int i = 0;
return ++i;

AtomicInteger ai = new AtomicInteger(0);
return ai.incrementAndGet();

Solution

No, I'm actually three instructions (load I, increment, store in I) This is definitely not atomic

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>