From db6fd89ae6c85056bd90bc325689be7d11ed5b75 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 28 Oct 2017 12:11:39 +1300 Subject: Atomic statistics check (fix #3614) --- src/org/traccar/database/StatisticsManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index 06a3e7b35..9a3ff06bd 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -27,12 +27,13 @@ import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; public class StatisticsManager { private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH; - private int lastUpdate = Calendar.getInstance().get(SPLIT_MODE); + private AtomicInteger lastUpdate = new AtomicInteger(Calendar.getInstance().get(SPLIT_MODE)); private Set users = new HashSet<>(); private Set devices = new HashSet<>(); @@ -47,7 +48,7 @@ public class StatisticsManager { private void checkSplit() { int currentUpdate = Calendar.getInstance().get(SPLIT_MODE); - if (lastUpdate != currentUpdate) { + if (lastUpdate.getAndSet(currentUpdate) != currentUpdate) { Statistics statistics = new Statistics(); statistics.setCaptureTime(new Date()); statistics.setActiveUsers(users.size()); @@ -96,7 +97,6 @@ public class StatisticsManager { smsSent = 0; geocoderRequests = 0; geolocationRequests = 0; - lastUpdate = currentUpdate; } } -- cgit v1.2.3