my Spring context was not closing properly and the JMS Connection factory was being managed by my spring container therefore it caused the leak.
Spring JmsTemplate's Daemon threads that stay alive after stopping tomcat application
-
14-06-2023 - |
Question
I am sending a message to IBM WebSphere MQ(the mq jar version is 7.0.1.9 and javax.jms is 1.1) using a Spring JmsTemplate class from my web application.
The connectionFactory i am using is MQQueueConnectionFactory.
The following daemon threads are created on executing send() on JmsTempalte and on instantiating MQQueueConnectionFactory.
PROBLEM
I am getting a message on tomcat command line showing these three threads as memory leaks when i stop the web application in the tomcat admin page. The daemon threads are
FROM JCONSOLE
THREAD 1
Name: JMSCCThreadPoolMaster State: WAITING on java.lang.Object@9f6e3e9 Total blocked: 3 Total waited: 4
Stack trace: java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:485) com.ibm.msg.client.commonservices.j2se.workqueue.WorkQueueManagerImplementation$WorkQueueManagerThread.waitForNotification(WorkQueueManagerImplementation.java:651) com.ibm.msg.client.commonservices.j2se.workqueue.WorkQueueManagerImplementation$WorkQueueManagerThread.waitForNotification(WorkQueueManagerImplementation.java:621) com.ibm.msg.client.commonservices.j2se.workqueue.WorkQueueManagerImplementation$WorkQueueManagerThread.run(WorkQueueManagerImplementation.java:887)
THREAD 2
Name: JMSCCThreadPoolWorker-2 State: WAITING on com.ibm.mq.jmqi.remote.internal.RemoteReconnectThread$ReconnectMutex@3d3c3e45 Total blocked: 0 Total waited: 1
Stack trace: java.lang.Object.wait(Native Method) java.lang.Object.wait(Object.java:485) com.ibm.mq.jmqi.remote.internal.RemoteReconnectThread.bestHconn(RemoteReconnectThread.java:672) com.ibm.mq.jmqi.remote.internal.RemoteReconnectThread.run(RemoteReconnectThread.java:129) com.ibm.msg.client.commonservices.workqueue.WorkQueueItem.runTask(WorkQueueItem.java:209) com.ibm.msg.client.commonservices.workqueue.SimpleWorkQueueItem.runItem(SimpleWorkQueueItem.java:100) com.ibm.msg.client.commonservices.workqueue.WorkQueueItem.run(WorkQueueItem.java:224) com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.runWorkQueueItem(WorkQueueManager.java:298) com.ibm.msg.client.commonservices.j2se.workqueue.WorkQueueManagerImplementation$ThreadPoolWorker.run(WorkQueueManagerImplementation.java:1220)
THREAD 3 (Dies after a min)
THIS ONE is created on instantiation of MQQueueConnectionFactory
Name: WebSphere MQ Trace Monitor State: TIMED_WAITING Total blocked: 0 Total waited: 5
Stack trace: java.lang.Thread.sleep(Native Method) com.ibm.mq.commonservices.internal.monitor.TraceMonitor.run(TraceMonitor.java:134)
How to make sure these daemon threads die.
La solution 2
Autres conseils
I believe that problem is within WMQ client jars and not within spring. Remove client jars from application and provide them at higher classloader level like coping them within tomcat/lib folder. This will not solve the problem, but work around it, as all applications will share common base and no leak will happen on application restart.