activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1378098 - in /activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool: ConnectionPool.java PooledConnection.java PooledSession.java
Date Tue, 28 Aug 2012 12:11:59 GMT
Author: gtully
Date: Tue Aug 28 12:11:58 2012
New Revision: 1378098

URL: http://svn.apache.org/viewvc?rev=1378098&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3997 - Memory leak in activemq-pool. Apply patch
from claus with thanks, removes duplicate listener registration

Modified:
    activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java
    activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java
    activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledSession.java

Modified: activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java?rev=1378098&r1=1378097&r2=1378098&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java
(original)
+++ activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java
Tue Aug 28 12:11:58 2012
@@ -19,10 +19,10 @@ package org.apache.activemq.pool;
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicBoolean;
-
 import javax.jms.JMSException;
 import javax.jms.Session;
 
@@ -39,7 +39,7 @@ public class ConnectionPool {
 
     private ActiveMQConnection connection;
     private ConcurrentHashMap<SessionKey, SessionPool> cache;
-    private ConcurrentLinkedQueue<PooledSession> loanedSessions = new ConcurrentLinkedQueue<PooledSession>();
+    private List<PooledSession> loanedSessions = new CopyOnWriteArrayList<PooledSession>();
     private AtomicBoolean started = new AtomicBoolean(false);
     private int referenceCount;
     private ObjectPoolFactory poolFactory;

Modified: activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java?rev=1378098&r1=1378097&r2=1378098&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java
(original)
+++ activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java
Tue Aug 28 12:11:58 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.pool;
 
+import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.jms.Connection;
@@ -54,13 +55,13 @@ import org.slf4j.LoggerFactory;
  * href="http://jencks.org/Message+Driven+POJOs">this example</a>
  *
  */
-public class PooledConnection implements TopicConnection, QueueConnection, EnhancedConnection
{
+public class PooledConnection implements TopicConnection, QueueConnection, EnhancedConnection,
PooledSessionEventListener {
     private static final transient Logger LOG = LoggerFactory.getLogger(PooledConnection.class);
 
     private ConnectionPool pool;
-    private boolean stopped;
-    private final CopyOnWriteArrayList<TemporaryQueue> connTempQueues = new CopyOnWriteArrayList<TemporaryQueue>();
-    private final CopyOnWriteArrayList<TemporaryTopic> connTempTopics = new CopyOnWriteArrayList<TemporaryTopic>();
+    private volatile boolean stopped;
+    private final List<TemporaryQueue> connTempQueues = new CopyOnWriteArrayList<TemporaryQueue>();
+    private final List<TemporaryTopic> connTempTopics = new CopyOnWriteArrayList<TemporaryTopic>();
 
     public PooledConnection(ConnectionPool pool) {
         this.pool = pool;
@@ -151,20 +152,17 @@ public class PooledConnection implements
 
         // Add a temporary destination event listener to the session that notifies us when
         // the session creates temporary destinations.
-        result.addTempDestEventListener(new PooledSessionEventListener() {
+        result.addTempDestEventListener(this);
+        return (Session) result;
+    }
 
-            @Override
-            public void onTemporaryQueueCreate(TemporaryQueue tempQueue) {
-                connTempQueues.add(tempQueue);
-            }
 
-            @Override
-            public void onTemporaryTopicCreate(TemporaryTopic tempTopic) {
-                connTempTopics.add(tempTopic);
-            }
-        });
+    public void onTemporaryQueueCreate(TemporaryQueue tempQueue) {
+        connTempQueues.add(tempQueue);
+    }
 
-        return (Session) result;
+    public void onTemporaryTopicCreate(TemporaryTopic tempTopic) {
+        connTempTopics.add(tempTopic);
     }
 
     // EnhancedCollection API

Modified: activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledSession.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledSession.java?rev=1378098&r1=1378097&r2=1378098&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledSession.java
(original)
+++ activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledSession.java
Tue Aug 28 12:11:58 2012
@@ -78,7 +78,10 @@ public class PooledSession implements Se
     }
 
     public void addTempDestEventListener(PooledSessionEventListener listener) {
-        this.tempDestEventListeners.add(listener);
+        // only add if really needed
+        if (!tempDestEventListeners.contains(listener)) {
+            this.tempDestEventListeners.add(listener);
+        }
     }
 
     protected boolean isIgnoreClose() {
@@ -123,6 +126,7 @@ public class PooledSession implements Se
             } finally {
                 consumers.clear();
                 browsers.clear();
+                tempDestEventListeners.clear();
             }
 
             if (invalidate) {



Mime
View raw message