JAVA-17608 Restored AtomicInteger default increment method

This commit is contained in:
Anastasios Ioannidis
2023-01-20 18:33:28 +02:00
parent 8103e7087b
commit ed51bc4cda
3 changed files with 26 additions and 12 deletions
@@ -1,7 +1,7 @@
package com.baeldung.concurrent.atomic;
public class SafeCounterWithLock {
private volatile int counter;
private int counter;
int getValue() {
return counter;
@@ -10,12 +10,6 @@ public class SafeCounterWithoutLock {
}
void increment() {
while(true) {
int existingValue = getValue();
int newValue = existingValue + 1;
if(counter.compareAndSet(existingValue, newValue)) {
return;
}
}
counter.incrementAndGet();
}
}