use Thread.isAlive()

This commit is contained in:
Milos Kozak 2018-07-20 17:52:31 +02:00
parent cfee405914
commit ab70d5b67d

View file

@ -392,10 +392,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
time = roundUpTime(previous); time = roundUpTime(previous);
AutosensData data = autosensDataTable.get(time); AutosensData data = autosensDataTable.get(time);
if (data != null) { if (data != null) {
//log.debug(">>> getAutosensData Cache hit " + data.log(time)); //log.debug(">>> AUTOSENSDATA Cache hit " + data.toString());
return data; return data;
} else { } else {
// log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString()); //log.debug(">>> AUTOSENSDATA Cache miss " + new Date(time).toLocaleString());
return null; return null;
} }
} }
@ -403,13 +403,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
@Nullable @Nullable
public AutosensData getLastAutosensDataSynchronized(String reason) { public AutosensData getLastAutosensDataSynchronized(String reason) {
if (thread != null && thread.getState() != Thread.State.TERMINATED) { if (thread != null && thread.isAlive()) {
log.debug("getLastAutosensDataSynchronized is waiting for calculation thread: " + reason); log.debug("AUTOSENSDATA is waiting for calculation thread: " + reason);
try { try {
thread.join(5000); thread.join(5000);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
log.debug("getLastAutosensDataSynchronized finished waiting for calculation thread: " + reason); log.debug("AUTOSENSDATA finished waiting for calculation thread: " + reason);
} }
synchronized (dataLock) { synchronized (dataLock) {
return getLastAutosensData(reason); return getLastAutosensData(reason);
@ -464,6 +464,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
log.debug("AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time)); log.debug("AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time));
return null; return null;
} else { } else {
log.debug("AUTOSENSDATA (" + reason + ") " + data.toString());
return data; return data;
} }
} }