diff --git a/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java b/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java index b2502018bb..38633011bf 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java +++ b/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java @@ -1,7 +1,7 @@ package com.baeldung.concurrent.atomic; public class SafeCounterWithLock { - int counter; + private volatile int counter; public int getValue() { return counter; diff --git a/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java b/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java index 55226f4f13..41e10789a6 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java +++ b/core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java @@ -3,7 +3,7 @@ package com.baeldung.concurrent.atomic; import java.util.concurrent.atomic.AtomicInteger; public class SafeCounterWithoutLock { - AtomicInteger counter = new AtomicInteger(0); + private final AtomicInteger counter = new AtomicInteger(0); public int getValue() { return counter.get();