diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java index e52735260d..ede1b01ede 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java @@ -390,8 +390,24 @@ public class ActiveMQActivation { } } - for (ActiveMQMessageHandler handler : handlersCopy) { - handler.teardown(); + Thread threadTearDown = new Thread("TearDown/ActiveMQActivation") { + @Override + public void run() { + for (ActiveMQMessageHandler handler : handlersCopy) { + handler.teardown(); + } + } + }; + + // We will first start a new thread that will call tearDown on all the instances, trying to graciously shutdown everything. + // We will then use the call-timeout to determine a timeout. + // if that failed we will then close the connection factory, and interrupt the thread + threadTearDown.start(); + + try { + threadTearDown.join(timeout); + } catch (InterruptedException e) { + // nothing to be done on this context.. we will just keep going as we need to send an interrupt to threadTearDown and give up } if (factory != null) { @@ -405,6 +421,20 @@ public class ActiveMQActivation { factory = null; } + if (threadTearDown.isAlive()) { + threadTearDown.interrupt(); + + try { + threadTearDown.join(5000); + } catch (InterruptedException e) { + // nothing to be done here.. we are going down anyways + } + + if (threadTearDown.isAlive()) { + ActiveMQRALogger.LOGGER.threadCouldNotFinish(threadTearDown.toString()); + } + } + nodes.clear(); lastReceived = false; @@ -518,7 +548,9 @@ public class ActiveMQActivation { calculatedDestinationName = spec.getQueuePrefix() + calculatedDestinationName; } - logger.debug("Unable to retrieve " + destinationName + " from JNDI. Creating a new " + destinationType.getName() + " named " + calculatedDestinationName + " to be used by the MDB."); + logger.debug("Unable to retrieve " + destinationName + + " from JNDI. Creating a new " + destinationType.getName() + + " named " + calculatedDestinationName + " to be used by the MDB."); // If there is no binding on naming, we will just create a new instance if (isTopic) {