3 Replies Latest reply on Jun 24, 2006 6:53 AM by timfox

    Can not find a free port for use

    jksmartt

      I am using a durableSubscriber with JBoss Messaging. After running for a while and publishing to topics and retrieving them with the durableSubscriber I get the following error:

      java.io.IOException: Can not find a free port for use.


      I am not sure why I am getting this, I am pretty sure I am closing the connections after I check to see if there are new messages. I can run for about 50 receiveNoWait calls before it dies:

      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("/ConnectionFactory");
      TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
      TopicConnection conn = tcf.createTopicConnection("testuser", "testpassword");
      conn.setClientID("testclient");
      TopicSession session = conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
      Topic topic = (Topic) iniCtx.lookup("topic/someTopic");
      
      conn.start();
      TopicSubscriber topicSubscriber = session.createDurableSubscriber(topic, "testclient");
      
      System.out.println("starting close topic: " + topicName);
      TextMessage tm = (TextMessage) topicSubscriber.receiveNoWait();
      topicSubscriber.close();
      conn.stop();
      session.close();
      conn.close();
      iniCtx.close();
      conn = null;


        • 1. Re: Can not find a free port for use
          timfox

          Creating connections is (relatively) a very slow process, so you should avoid creating them every time you want to check a message (it's an anti-pattern creating a connection every time).

          Also your call to session.close() is redundant since you're calling conn.close() which will close the session too.

          • 2. Re: Can not find a free port for use
            jksmartt

            Yes, that was the problem. I am using the JBoss Messenging within a Portlet so I set the TopicConnection into the PortletSession and now reuse it over and over within that session.

            Thx!

            • 3. Re: Can not find a free port for use
              timfox

              Also, I have changed the code so that less callback servers wil be created. This means we will be able to support more concurrent open jms connections on the client side.

              This will be available in RC3