mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3997 - Memory leak in activemq-pool. Apply patch from claus with thanks, removes duplicate listener registration
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1378098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d41f40a051
commit
b496c0a38c
|
@ -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;
|
||||
|
|
|
@ -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,22 +152,19 @@ public class PooledConnection implements TopicConnection, QueueConnection, Enhan
|
|||
|
||||
// Add a temporary destination event listener to the session that notifies us when
|
||||
// the session creates temporary destinations.
|
||||
result.addTempDestEventListener(new PooledSessionEventListener() {
|
||||
|
||||
@Override
|
||||
public void onTemporaryQueueCreate(TemporaryQueue tempQueue) {
|
||||
connTempQueues.add(tempQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTemporaryTopicCreate(TemporaryTopic tempTopic) {
|
||||
connTempTopics.add(tempTopic);
|
||||
}
|
||||
});
|
||||
|
||||
result.addTempDestEventListener(this);
|
||||
return (Session) result;
|
||||
}
|
||||
|
||||
|
||||
public void onTemporaryQueueCreate(TemporaryQueue tempQueue) {
|
||||
connTempQueues.add(tempQueue);
|
||||
}
|
||||
|
||||
public void onTemporaryTopicCreate(TemporaryTopic tempTopic) {
|
||||
connTempTopics.add(tempTopic);
|
||||
}
|
||||
|
||||
// EnhancedCollection API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -78,7 +78,10 @@ public class PooledSession implements Session, TopicSession, QueueSession, XASes
|
|||
}
|
||||
|
||||
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 Session, TopicSession, QueueSession, XASes
|
|||
} finally {
|
||||
consumers.clear();
|
||||
browsers.clear();
|
||||
tempDestEventListeners.clear();
|
||||
}
|
||||
|
||||
if (invalidate) {
|
||||
|
|
Loading…
Reference in New Issue