diff --git a/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/jms/JMSTask.java b/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/jms/JMSTask.java index ec2bf6262c..56e9ddd551 100644 --- a/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/jms/JMSTask.java +++ b/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/jms/JMSTask.java @@ -43,7 +43,11 @@ public JMSTask(JMSPollingConsumer jmsPollingConsumer, long interval) { protected void taskExecute() { logger.debug("Executing JMS Task Execution."); - jmsPollingConsumer.execute(); + if (jmsPollingConsumer != null) { + jmsPollingConsumer.execute(); + } else { + logger.error("JMS Polling Consumer is closed. Cannot execute the task."); + } } @Override @@ -58,6 +62,8 @@ public void init(SynapseEnvironment synapseEnvironment) { public void destroy() { logger.debug("Destroying JMS Task."); jmsPollingConsumer.destroy(); + // removing the consumer reference to avoid dangling consumers in broker side. + jmsPollingConsumer = null; } /**