From 9c4042eb88480cc4f9ca64179c264ce714fb173c Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 24 Jul 2017 08:49:36 +0200 Subject: [PATCH] Add missing "volatile"s (#2307) * Add volatile keywords * Update SafeCounterWithoutLock.java --- .../com/baeldung/concurrent/atomic/SafeCounterWithLock.java | 2 +- .../com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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();