Home>Article>Java> How to use LongAdder counter in java

How to use LongAdder counter in java

PHPz
PHPz forward
2023-04-28 20:28:11 815browse

Use LongAdder counter

In the case of high contention, java.util.concurrent.atomic.LongAdder will be used for counting instead of AtomicLong/AtomicInteger.

LongAdder can keep the same value across multiple units, but if necessary, they can also increase their value, but compared with the parent class AtomicXX, this will result in higher throughput and will also increase memory consumption.

LongAdder counter = new LongAdder(); counter.increment(); ... long currentValue = counter.sum();

The above is the detailed content of How to use LongAdder counter in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete