LongAdder class differences and class AtomicLong

LongAdder classes and class distinction AtomicLong in that the former high concurrency CAS will operate as a single variable dispersion CAS array of cells in the plurality of operating elements, when the summed value; when performed only in the lower base variable concurrency CAS operation, the same principle AtomicLong class. This distributed design have to say is very clever. Faster atomic class: LongAdder
we should be more understanding of the implementation mechanism AtomicInteger, which is in an infinite loop, and continuously try to modify the target value, aware of the amendment is successful, if the competition is not fierce, then modify the probability of success is high, otherwise, modify the probability of failure is high, when a large number of modification fails, these atomic operations will be carried out repeatedly to cycle, so the performance will be affected
less intense competition, we should be how to further improve the system performance? One the basic solution is to use separate hotspot, the competition data decomposition. based on this idea, it should blow conceivable An improved method for the traditional class AtomicInteger other atoms, while CAS no lock operation, but such as to reduce the lock granularity ideas isolated hot spots are still available, one possible solution is to mimic ConcurrengHashMap, the hot data separation, for instance, value can be separated AtomicInteger internal core data into an array, each thread access by mapping hash algorithms wherein a number counts, and the final count result, compared with the number of Cumulative summation group, wherein the hot data value is separated into a plurality of cell units, each cell maintains its own internal value, the actual value of the target current accumulated synthesized from all the cell, so that, for an effective hot spot separation, improve the degree of parallelism, LongAdder this idea is the use of inaccurate results .LongAdder problem may occur when the combined statistics of each cell, so the serial number for the high accuracy requirements of this variable can not be used LongAdder

Reproduced in: https: //www.jianshu.com/p/1e665378a83f

Guess you like

Origin blog.csdn.net/weixin_34315665/article/details/91052242