diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java index 3790f365ac..35ea4f59b0 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java @@ -196,8 +196,11 @@ public class AMQPConnectionContext extends ProtonInitializable implements EventH if (scheduledPool != null && scheduledPool instanceof ThreadPoolExecutor && scheduledFuture != null && scheduledFuture instanceof Runnable) { - if (!((ThreadPoolExecutor) scheduledPool).remove((Runnable) scheduledFuture)) { + if (!((ThreadPoolExecutor) scheduledPool).remove((Runnable) scheduledFuture) && + !scheduledFuture.isCancelled() && !scheduledFuture.isDone()) { log.warn("Scheduled task can't be removed from scheduledPool."); + } else { + scheduledFuture = null; } } } diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContextTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContextTest.java index 8bdda7ec75..13b0258d2f 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContextTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContextTest.java @@ -81,6 +81,6 @@ public class AMQPConnectionContextTest { connectionContext.close(null); - Assert.assertEquals(0, scheduledPool.getTaskCount()); + Assert.assertEquals(0, scheduledPool.getQueue().size()); } }