From d0bcf2eca3ff91fa69b20aabc8b6c57b789fb0ff Mon Sep 17 00:00:00 2001 From: Hao Kuang Date: Fri, 25 Aug 2017 16:15:26 +0000 Subject: Fix that APP-C LCM Command Running After OAM Stop The fix code does that waiting for threads in the queue completely interrupted than let bundle:stop() method return. Issue-Id: APPC-162 Change-Id: I8b34fc48fd2ae5ae1ad67d11ee3ad5f349171b47 Signed-off-by: Hao Kuang --- .../appc/executionqueue/impl/QueueManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src') diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java index b78f399e0..9e1efb644 100644 --- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java +++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java @@ -30,6 +30,7 @@ import org.openecomp.appc.executionqueue.MessageExpirationListener; import org.openecomp.appc.executionqueue.helper.Util; import org.openecomp.appc.executionqueue.impl.object.QueueMessage; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; @@ -70,7 +71,23 @@ public class QueueManager { * Destory method used by blueprint */ public void stop() { - messageExecutor.shutdownNow(); + // Disable new tasks from being submitted + messageExecutor.shutdown(); + List rejectedRunnables = messageExecutor.shutdownNow(); + logger.info(String.format("Rejected %d waiting tasks include ", rejectedRunnables.size())); + + try { + messageExecutor.shutdownNow(); // Cancel currently executing tasks + // Wait a while for tasks to respond to being cancelled + while (!messageExecutor.awaitTermination(100, TimeUnit.MILLISECONDS)) { + logger.debug("QueueManager is being shut down because it still has threads not interrupted"); + } + } catch (InterruptedException ie) { + // (Re-)Cancel if current thread also interrupted + messageExecutor.shutdownNow(); + // Preserve interrupt status + Thread.currentThread().interrupt(); + } } public void setListener(MessageExpirationListener listener) { -- cgit 1.2.3-korg