Java – Atomic increment of long variables?
•
Java
If the long variable is declared as: –
Long counter = 0;
Now, if I use the pre increment operator to increment it, is the operation atomic?
If so, it will be better than Java util. concurrent. atomic. Is the increment of atomiclong objects more efficient?
Solution
The volatile keyword can only solve the visibility problem You must use atomiclong or atomicity in concurrent programming of synchronized methods / blocks
Another article today: demonstrating when volatile is required
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
二维码