diff options
author | Abyss777 <abyss@fox5.ru> | 2016-07-19 16:54:13 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-07-19 16:54:13 +0500 |
commit | b91d1b41343a1d3d8625c1dc42c9c7d2244fb903 (patch) | |
tree | 65067a5551067d4fa6d8cfe69c0d0f4d3723706c /src/org/traccar | |
parent | 00e2f8a3575855a8b863e245005b8f83b3314bfb (diff) | |
download | traccar-server-b91d1b41343a1d3d8625c1dc42c9c7d2244fb903.tar.gz traccar-server-b91d1b41343a1d3d8625c1dc42c9c7d2244fb903.tar.bz2 traccar-server-b91d1b41343a1d3d8625c1dc42c9c7d2244fb903.zip |
Split locks in GeofenceManager and try to avoid crosslocks with devices.
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/database/GeofenceManager.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index dc31172b9..2994920d9 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -155,25 +155,34 @@ public class GeofenceManager { public final void refresh() { if (dataManager != null) { try { + + Collection<GroupGeofence> databaseGroupGeofences = dataManager.getGroupGeofences(); groupGeofencesLock.writeLock().lock(); - deviceGeofencesLock.writeLock().lock(); try { groupGeofences.clear(); - for (GroupGeofence groupGeofence : dataManager.getGroupGeofences()) { + for (GroupGeofence groupGeofence : databaseGroupGeofences) { getGroupGeofences(groupGeofence.getGroupId()).add(groupGeofence.getGeofenceId()); } + } finally { + groupGeofencesLock.writeLock().unlock(); + } + Collection<DeviceGeofence> databaseDeviceGeofences = dataManager.getDeviceGeofences(); + Collection<Device> allDevices = Context.getDeviceManager().getAllDevices(); + + deviceGeofencesLock.writeLock().lock(); + try { deviceGeofences.clear(); deviceGeofencesWithGroups.clear(); - for (DeviceGeofence deviceGeofence : dataManager.getDeviceGeofences()) { + for (DeviceGeofence deviceGeofence : databaseDeviceGeofences) { getDeviceGeofences(deviceGeofences, deviceGeofence.getDeviceId()) .add(deviceGeofence.getGeofenceId()); getDeviceGeofences(deviceGeofencesWithGroups, deviceGeofence.getDeviceId()) .add(deviceGeofence.getGeofenceId()); } - for (Device device : Context.getDeviceManager().getAllDevices()) { + for (Device device : allDevices) { long groupId = device.getGroupId(); while (groupId != 0) { getDeviceGeofences(deviceGeofencesWithGroups, @@ -204,7 +213,6 @@ public class GeofenceManager { } } finally { - groupGeofencesLock.writeLock().unlock(); deviceGeofencesLock.writeLock().unlock(); } |