From cfee405914e44284c4cc78408e97831bdbd2646f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 20 Jul 2018 10:52:58 +0200 Subject: [PATCH] use thread.join --- .../IobCobCalculator/IobCobCalculatorPlugin.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index a81bd81fcf..e848645d1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -403,9 +403,13 @@ public class IobCobCalculatorPlugin extends PluginBase { @Nullable public AutosensData getLastAutosensDataSynchronized(String reason) { - while (thread != null && thread.getState() != Thread.State.TERMINATED) { - SystemClock.sleep(100); - log.debug("getLastAutosensDataSynchronized is waiting for calculation thread"); + if (thread != null && thread.getState() != Thread.State.TERMINATED) { + log.debug("getLastAutosensDataSynchronized is waiting for calculation thread: " + reason); + try { + thread.join(5000); + } catch (InterruptedException ignored) { + } + log.debug("getLastAutosensDataSynchronized finished waiting for calculation thread: " + reason); } synchronized (dataLock) { return getLastAutosensData(reason); @@ -505,14 +509,10 @@ public class IobCobCalculatorPlugin extends PluginBase { public AutosensResult detectSensitivityWithLock(long fromTime, long toTime) { synchronized (dataLock) { - return detectSensitivity(fromTime, toTime); + return ConfigBuilderPlugin.getActiveSensitivity().detectSensitivity(fromTime, toTime); } } - static AutosensResult detectSensitivity(long fromTime, long toTime) { - return ConfigBuilderPlugin.getActiveSensitivity().detectSensitivity(fromTime, toTime); - } - public static JSONArray convertToJSONArray(IobTotal[] iobArray) { JSONArray array = new JSONArray(); for (int i = 0; i < iobArray.length; i++) {