From 08841bbde3456939376f1940789c9a7b88b7a6c0 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Wed, 3 Oct 2007 18:50:03 +0000 Subject: [PATCH] fix memory leak in ActiveMQConnection - with asyncConnectionThread not being shutdown on a close git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@581683 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/ActiveMQConnection.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java index 16b6836b62..cb9a892e90 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -593,6 +593,10 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon // then we may need to call // factory.onConnectionClose(this); sessionTaskRunner.shutdown(); + + if (asyncConnectionThread != null){ + asyncConnectionThread.shutdown(); + } closed.set(true); closing.set(false); @@ -1652,20 +1656,23 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon } public void onException(final IOException error) { - onAsyncException(error); - asyncConnectionThread.execute(new Runnable() { - public void run() { - transportFailed(error); - ServiceSupport.dispose(ActiveMQConnection.this.transport); - brokerInfoReceived.countDown(); + onAsyncException(error); + if (!closing.get() && !closed.get()) { + asyncConnectionThread.execute(new Runnable() { + public void run() { + transportFailed(error); + ServiceSupport.dispose(ActiveMQConnection.this.transport); + brokerInfoReceived.countDown(); - for (Iterator iter = transportListeners.iterator(); iter.hasNext();) { - TransportListener listener = iter.next(); - listener.onException(error); - } - } - }); - } + for (Iterator iter = transportListeners + .iterator(); iter.hasNext();) { + TransportListener listener = iter.next(); + listener.onException(error); + } + } + }); + } + } public void transportInterupted() { for (Iterator i = this.sessions.iterator(); i.hasNext();) {