Atomically incrementing counters stored in ConcurrentHashMap

前端 未结 6 1465
猫巷女王i
猫巷女王i 2020-12-05 04:02

I would like to collect some metrics from various places in a web app. To keep it simple, all these will be counters and therefore the only modifier operation is to incremen

6条回答
  •  悲哀的现实
    2020-12-05 04:50

    I did a benchmark to compare the performance of LongAdder and AtomicLong.

    LongAdder had a better performance in my benchmark: for 500 iterations using a map with size 100 (10 concurrent threads), the average time for LongAdder was 1270ms while that for AtomicLong was 1315ms.

提交回复
热议问题