diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-20 00:35:35 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-20 00:35:35 +1200 |
commit | d98cd05a989bd0cd3f6dd4c581e46b0cbbd6424a (patch) | |
tree | 6b73770f8e8e27051dc0efadd3afafa1517d2842 | |
parent | 00e2f8a3575855a8b863e245005b8f83b3314bfb (diff) | |
parent | 6ef76c9e22ada4ed5d89d0a3bd43d759b56bebe0 (diff) | |
download | trackermap-server-d98cd05a989bd0cd3f6dd4c581e46b0cbbd6424a.tar.gz trackermap-server-d98cd05a989bd0cd3f6dd4c581e46b0cbbd6424a.tar.bz2 trackermap-server-d98cd05a989bd0cd3f6dd4c581e46b0cbbd6424a.zip |
Merge pull request #2129 from Abyss777/fix_locks_in_geofense_refresh
Split locks in GeofenceManager to avoid dead locks
-rw-r--r-- | src/org/traccar/database/GeofenceManager.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index dc31172b9..930008082 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -155,25 +155,35 @@ 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(); + + groupGeofencesLock.readLock().lock(); + 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,8 +214,8 @@ public class GeofenceManager { } } finally { - groupGeofencesLock.writeLock().unlock(); deviceGeofencesLock.writeLock().unlock(); + groupGeofencesLock.readLock().unlock(); } } catch (SQLException error) { |