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.