diff --git a/module/dal/control/src/main/java/org/openbase/bco/dal/control/action/ActionImpl.java b/module/dal/control/src/main/java/org/openbase/bco/dal/control/action/ActionImpl.java index 49434d7ec4..6b916c3797 100644 --- a/module/dal/control/src/main/java/org/openbase/bco/dal/control/action/ActionImpl.java +++ b/module/dal/control/src/main/java/org/openbase/bco/dal/control/action/ActionImpl.java @@ -80,6 +80,13 @@ public class ActionImpl implements SchedulableAction { private ServiceDescription serviceDescription; private volatile Future actionTask; + /** + * This flag ist required to handle the case when the action task was + * initiated but never started because of any interruption. + * In this case the flag is false but the actionTask non null. + */ + private volatile Boolean actionTaskRunning = false; + /** * Constructor creates a new action object which helps to manage its execution during the scheduling process. *

@@ -198,7 +205,7 @@ private boolean isActionTaskFinished() { // when the action task finishes it will finally reset the action task to null. // actionTask.isDone(); is not a solution at all because when the action task is // canceled then the method already returns true but the task is maybe still running. - return actionTask == null; + return actionTask == null || !actionTaskRunning; } } @@ -256,7 +263,9 @@ public Future execute() { new FatalImplementationErrorException("Action task still running while initializing a new one.", this); } + actionTaskRunning = false; actionTask = GlobalCachedExecutorService.submit(() -> { + actionTaskRunning = true; try { // validate operation service @@ -362,6 +371,7 @@ public Future execute() { } } finally { actionTask = null; + actionTaskRunning = false; synchronized (actionTaskLock) { actionTaskLock.notifyAll(); } @@ -728,6 +738,14 @@ private void cancelActionTask() { // cancel if exist if (actionTask != null) { actionTask.cancel(true); + + // if the task is canceled before it is scheduled, we need to notify + // all waiting tasks about the cancellation + synchronized (actionTaskLock) { + if (!actionTaskRunning) { + actionTaskLock.notifyAll(); + } + } } try {