Skip to content

Commit 9c4042e

Browse files
authored
Add missing "volatile"s (eugenp#2307)
* Add volatile keywords * Update SafeCounterWithoutLock.java
1 parent ef5013c commit 9c4042e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithLock.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.baeldung.concurrent.atomic;
22

33
public class SafeCounterWithLock {
4-
int counter;
4+
private volatile int counter;
55

66
public int getValue() {
77
return counter;

‎core-java/src/main/java/com/baeldung/concurrent/atomic/SafeCounterWithoutLock.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.concurrent.atomic.AtomicInteger;
44

55
public class SafeCounterWithoutLock {
6-
AtomicInteger counter = new AtomicInteger(0);
6+
private final AtomicInteger counter = new AtomicInteger(0);
77

88
public int getValue() {
99
return counter.get();

0 commit comments

Comments
 (0)