Java int concurrency int is equivalent to atomicinteger incrementAndGet()?
•
Java
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
二维码