Reputation: 340
It seems the JMSProducer
is not getting garbage collected and keeps alive after delivering messages to queue, I'm using Spring 3.2.2 and CachingConnectionFactory
with Keep-alive setting for sending message.
Producers count keeps increasing every time I send message.
Is it related to spring version I am using?
or am I doing something wrong in my configuration?
Upvotes: 0
Views: 631
Reputation: 1685
You need to call close()
method on your MessageProducer
. As per the Java docs:-
void close() throws JMSException
Closes the message producer.
Since a provider may allocate some resources on behalf of a
MessageProducer
outside the Java virtual machine, clients should close them when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.
As per the spring CachingConnectionFactory docs :-
NOTE: This ConnectionFactory requires explicit closing of all Sessions obtained from its shared Connection. This is the usual recommendation for native JMS access code anyway. However, with this ConnectionFactory, its use is mandatory in order to actually allow for Session reuse.
So you need to call getCachedSessionProxy instead of getSession and once done with sending message call the close() (in finally block) . As per the source code, the close call to this Session proxy is handled such that the session and messageproducer is reused. Gary's comments states the same.
Upvotes: 1