I'm not an ActiveMQ expert and I have the following problem.
Running a web application in Tomcat 8.x, Java 8, Spring Framework 4.3.18.
My web application both sends and receives messages with ActiveMQ, using
I'm setting up an ActiveMQ connection factory in this way:
The last property ('maximumActiveSessionPerConnection') has been set to try
to solve the following problem (the default seems to be 500, which is quite
high IMHO), but I'm not sure it really helped, because I'm still getting
This connection factory is referenced by a listener container factory:
Things work well, but what I observe is that ActiveMQ, as a message producer
(for the invoiceEventJmsOutboundChannelAdapter adapter), is accumulating a
lot of objects in memory and it's causing OutOfMemory errors in my
application. My messages may be some KBs long, because their payloads are
XML files, but nevertheless I don't expect to hold so much memory for a long
Here are my findings on a heap dump produced on the most recent OutOfMemory
error (using Eclipse MAT to investigate). Two leak suspects are found and
both lead to ConnectionStateTracker.
As you can see, an instance of ConnectionStateTracker is retaining around 70
MB of heap space. There are two instances of ConnectionStateTracker (one for
each outbound adapter I guess) which are retaining a total of about 120 MB
of heap. They are accumulating it in two instances of ConnectionState, which
in turn have a map of "sessions" containing a cumulated total of 10
SessionState instances, which in turn have a ConcurrentHashMap of producers
holding a cumulated total of 1,258 ProducerState instances. These are
retaining those 120 MB of heap in their transactionState field, which is of
type TransactionState, which in turn has a commands ArrayList which seems to
be retaining the whole messages I'm sending out.
My question is: why ActiveMQ is keeping in memory the messages already sent
out? There are also some security concerns in keeping in memory all those