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!