Add missing "volatile"s (#2307)

* Add volatile keywords

* Update SafeCounterWithoutLock.java
This commit is contained in:
Grzegorz Piwowarek 2017-07-24 08:49:36 +02:00 committed by GitHub
parent ef5013ce24
commit 9c4042eb88
2 changed files with 2 additions and 2 deletions

View File

@ -1,7 +1,7 @@
package com.baeldung.concurrent.atomic;
public class SafeCounterWithLock {
int counter;
private volatile int counter;
public int getValue() {
return counter;

View File

@ -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();