From 97e7466352aec64c99f93b1979c1137efba324d2 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Mon, 29 Oct 2018 22:30:15 +0100 Subject: [PATCH] Fix UI freeze caused by OnlineMonitor The lock to prevent concurrent access to the list models caused the app to freeze, if the models list contained many models, because the OnlineMonitor would block access until it checked the online state of every model. --- .../java/ctbrec/recorder/LocalRecorder.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/ctbrec/recorder/LocalRecorder.java b/src/main/java/ctbrec/recorder/LocalRecorder.java index 4f3f983b..e1916d93 100644 --- a/src/main/java/ctbrec/recorder/LocalRecorder.java +++ b/src/main/java/ctbrec/recorder/LocalRecorder.java @@ -166,7 +166,12 @@ public class LocalRecorder implements Recorder { @Override public List getModelsRecording() { - return Collections.unmodifiableList(new ArrayList<>(models)); + lock.lock(); + try { + return Collections.unmodifiableList(new ArrayList<>(models)); + } finally { + lock.unlock(); + } } @Override @@ -308,24 +313,19 @@ public class LocalRecorder implements Recorder { public void run() { running = true; while (running) { - lock.lock(); - try { - for (Model model : getModelsRecording()) { - try { - if (!recordingProcesses.containsKey(model)) { - boolean isOnline = model.isOnline(IGNORE_CACHE); - LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline")); - if (isOnline) { - LOG.info("Model {}'s room back to public. Starting recording", model); - startRecordingProcess(model); - } + for (Model model : getModelsRecording()) { + try { + if (!recordingProcesses.containsKey(model)) { + boolean isOnline = model.isOnline(IGNORE_CACHE); + LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline")); + if (isOnline) { + LOG.info("Model {}'s room back to public. Starting recording", model); + startRecordingProcess(model); } - } catch (Exception e) { - LOG.error("Couldn't check if model {} is online", model.getName(), e); } + } catch (Exception e) { + LOG.error("Couldn't check if model {} is online", model.getName(), e); } - } finally { - lock.unlock(); } try {