mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-01-14 16:57:24 -05:00
make ClockWatcher thread safe
This commit is contained in:
parent
b0b5fde742
commit
b9ed399036
@ -54,6 +54,7 @@ public class ClockWatcher {
|
|||||||
if (timer == null) {
|
if (timer == null) {
|
||||||
lastSecondTick = System.currentTimeMillis();
|
lastSecondTick = System.currentTimeMillis();
|
||||||
timer = UserThread.runPeriodically(() -> {
|
timer = UserThread.runPeriodically(() -> {
|
||||||
|
synchronized (listeners) {
|
||||||
listeners.forEach(Listener::onSecondTick);
|
listeners.forEach(Listener::onSecondTick);
|
||||||
counter++;
|
counter++;
|
||||||
if (counter >= 60) {
|
if (counter >= 60) {
|
||||||
@ -73,6 +74,7 @@ public class ClockWatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastSecondTick = currentTimeMillis;
|
lastSecondTick = currentTimeMillis;
|
||||||
|
}
|
||||||
}, 1, TimeUnit.SECONDS);
|
}, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,10 +86,14 @@ public class ClockWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(Listener listener) {
|
public void addListener(Listener listener) {
|
||||||
|
synchronized (listeners) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeListener(Listener listener) {
|
public void removeListener(Listener listener) {
|
||||||
|
synchronized (listeners) {
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user