From b91d1b41343a1d3d8625c1dc42c9c7d2244fb903 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 19 Jul 2016 16:54:13 +0500 Subject: Split locks in GeofenceManager and try to avoid crosslocks with devices. --- src/org/traccar/database/GeofenceManager.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/org') 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 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 databaseDeviceGeofences = dataManager.getDeviceGeofences(); + Collection 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(); } -- cgit v1.2.3 From 6ef76c9e22ada4ed5d89d0a3bd43d759b56bebe0 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 19 Jul 2016 17:03:00 +0500 Subject: Missed groupGeofences read lock --- src/org/traccar/database/GeofenceManager.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index 2994920d9..930008082 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -170,6 +170,7 @@ public class GeofenceManager { Collection databaseDeviceGeofences = dataManager.getDeviceGeofences(); Collection allDevices = Context.getDeviceManager().getAllDevices(); + groupGeofencesLock.readLock().lock(); deviceGeofencesLock.writeLock().lock(); try { deviceGeofences.clear(); @@ -214,6 +215,7 @@ public class GeofenceManager { } finally { deviceGeofencesLock.writeLock().unlock(); + groupGeofencesLock.readLock().unlock(); } } catch (SQLException error) { -- cgit v1.2.3