-
Notifications
You must be signed in to change notification settings - Fork 703
Expand file tree
/
Copy pathCounter.java
More file actions
23 lines (19 loc) · 809 Bytes
/
Copy pathCounter.java
File metadata and controls
23 lines (19 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package core.basesyntax;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Counter {
private static final Logger logger = LogManager.getLogger(Counter.class);
private static final String MESSAGE = "%20s, Thread # %2s, counter value %2d";
private AtomicInteger value;
public Counter(AtomicInteger value) {
this.value = value;
}
public synchronized void decreaseValue() {
logger.info(String.format(MESSAGE,
"Before decrementing", Thread.currentThread().getName(), value.get()));
value.decrementAndGet();
logger.info(String.format(MESSAGE,
"After decrementing", Thread.currentThread().getName(), value.get()));
}
}