<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
hundreds of HornetQ threads on EAR multiple redeployments
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/karomann">Kamil Roman</a> in <i>JBoss Messaging</i> - <a href="https://community.jboss.org/message/808108#808108">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>recently I have experiences issued when multiple my EAR file onto JBoss EAP 6 multiple times in a short period of time (trying to set up integration testing with Arquillian) - after 10-20 redeployments I get a few hundreds of HornetQ threads running leading to server hang up. After some time the threads are no longer there (inactivity timeouts?), but automating the integration testing is not possible at all, as usually the threads have already caused OutOfMemoryError.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>What can be the root cause of this? Is there any workaround like e.g. setting shorter timeout period for the threads? I have searched my project for any references to javax.jms.* and I have found only one class containing them, I have pasted its code below. It seems to cache some JMS resources, however they should be freed in the @PreDestroy method.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="font-size: 10pt;"> </span> </p><p>@Stateless</p><p>public class JmsResponder {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          @Resource(lookup = "java:/queue/outqueue")</p><p>          private Queue outQueue;</p><p>  </p><p>          private String userName;</p><p>          private String password;</p><p>          private int jmsPortUsed;</p><p>  </p><p>          private HashMap&lt;String, JMSParams&gt; connCache;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          @PostConstruct</p><p>          private void init(){</p><p>                    userName = "myusername";</p><p>                    password = "mypassword";</p><p>                    jmsPortUsed = 1234;</p><p>                    connCache = new HashMap&lt;String, JMSParams&gt;();</p><p>          }</p><p>  </p><p>  </p><p>          @TransactionAttribute(TransactionAttributeType.NEVER)</p><p>          public void reply(String messageText, String address) {</p><p>      </p><p>                    QueueSender sender = null;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    try {</p><p>                              QueueSession sess = getSession(address);</p><p>                              Message msg = sess.createMessage();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              msg.setStringProperty("messageText", messageText);</p><p>                              sender = sess.createSender(outQueue);</p><p>                              sender.send(msg);</p><p>                    } catch (JMSException e) {</p><p>                                   e.printStackTrace();</p><p>                    } finally {</p><p>                              try {</p><p>                                        sender.close();</p><p>                              } catch (JMSException e) {</p><p>                                        e.printStackTrace();</p><p>                              }</p><p>                    }</p><p>          }</p><p>  </p><p>          private QueueSession getSession(String address) {</p><p>                    if (!connCache.containsKey(address)){</p><p>                              JMSParams params = new JMSParams();</p><p>                              try {</p><p>                                        Map&lt;String, Object&gt; connectionParams = new HashMap&lt;String, Object&gt;();</p><p>                                        connectionParams.put(TransportConstants.PORT_PROP_NAME, jmsPortUsed);</p><p>                                        connectionParams.put(TransportConstants.HOST_PROP_NAME, address);</p><p>                                        TransportConfiguration transportConfiguration = new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", connectionParams);</p><p>                                        params.connectionFactory = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);</p><p>                                        params.conn = params.connectionFactory.createQueueConnection(userName, password);</p><p>                                        params.sess = params.conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);</p><p>                                        connCache.put(address, params);</p><p>                              } catch (Exception e){</p><p>                                        LOG.error(e, e);</p><p>                                        if (params.sess != null){</p><p>                                                  try {</p><p>                                                            params.sess.close();</p><p>                                                  } catch (JMSException e1) {</p><p>                                                            LOG.error(e1, e1);</p><p>                                                  }</p><p>                                        }</p><p>                                        if (params.conn != null){</p><p>                                                  try {</p><p>                                                            params.conn.close();</p><p>                                                  } catch (JMSException e1) {</p><p>                                                            LOG.error(e1, e1);</p><p>                                                  }</p><p>                                        }</p><p>                                        if (params.connectionFactory != null){</p><p>                                                  params.connectionFactory.close();</p><p>                                        }</p><p>                              }</p><p>                    }</p><p>                    return connCache.get(address).sess;</p><p>          }</p><p>  </p><p>          private static class JMSParams {</p><p>                    QueueConnection conn = null;</p><p>                    QueueSession sess = null;</p><p>                    HornetQConnectionFactory connectionFactory = null;</p><p>          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          @PreDestroy</p><p>          private void destruct(){</p><p>                    for (JMSParams param : connCache.values()){</p><p>                              if (param.sess != null){</p><p>                                        try {</p><p>                                                  param.sess.close();</p><p>                                        } catch (JMSException e1) {</p><p>                                                  LOG.error(e1, e1);</p><p>                                        }</p><p>                              }</p><p>                              if (param.conn != null){</p><p>                                        try {</p><p>                                                  param.conn.close();</p><p>                                        } catch (JMSException e1) {</p><p>                                                  LOG.error(e1, e1);</p><p>                                        }</p><p>                              }</p><p>                              if (param.connectionFactory != null){</p><p>                                        param.connectionFactory.close();</p><p>                              }</p><p>                    }</p><p>          }</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am also attaching messaging subsystem configuration from my standalone.xml (messaging.txt) as well as thread dump from a sample reproduction of the issue (stack.txt). The sample thread dump contains only 45 HornetQ threads but on the machine I run it it was enough to hand the JBoss up. On stronger machine this number can reach a few hundrends. The tests that are run with Arquillin in the EAR does not use the JMS API at all.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/808108#808108">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Messaging at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>