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

How to use LongAdder counter in java

PHPz
Release: 2023-04-28 20:28:11
forward
913 people have browsed it

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();
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template