forked from j62/ctbrec
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.
This commit is contained in:
parent
093ca92b4a
commit
97e7466352
|
@ -166,7 +166,12 @@ public class LocalRecorder implements Recorder {
|
|||
|
||||
@Override
|
||||
public List<Model> 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 {
|
||||
|
|
Loading…
Reference in New Issue