forked from mate-academy/jv-multithreading-decrease-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.java
More file actions
22 lines (18 loc) · 707 Bytes
/
Copy pathCounter.java
File metadata and controls
22 lines (18 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package core.basesyntax;
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 int value;
public Counter(int value) {
this.value = value;
}
public synchronized void decreaseValue() {
logger.info(String.format(MESSAGE,
"Before decrementing", Thread.currentThread().getName(), value));
value--;
logger.info(String.format(MESSAGE,
"After decrementing", Thread.currentThread().getName(), value));
}
}