Add missing "volatile"s (#2307)
* Add volatile keywords * Update SafeCounterWithoutLock.java
This commit is contained in:
parent
ef5013ce24
commit
9c4042eb88
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.concurrent.atomic;
|
||||
|
||||
public class SafeCounterWithLock {
|
||||
int counter;
|
||||
private volatile int counter;
|
||||
|
||||
public int getValue() {
|
||||
return counter;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue