Using An AtomicLong With A Modulo Operation May Be Faster Than Using compareAndSet() For Thread-Safe Range-Based Counters

added by JavaScript Kicks
3/28/2018 7:11:44 AM

269 Views

Last week, I looked at using Java's AtomicInteger class in order to loop over a range of numbers in a thread-safe manner without having to add any additional locking to the code. The core of the logic revolved around executing a while(true) loop that repeatedly invoked a .compareAndSet() method until it returned successfully.


0 comments