JAVA-17608 Restored AtomicInteger default increment method
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.concurrent.atomic;
|
||||
|
||||
public class SafeCounterWithLock {
|
||||
private volatile int counter;
|
||||
private int counter;
|
||||
|
||||
int getValue() {
|
||||
return counter;
|
||||
|
||||
+1
-7
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user