1 Reply Latest reply on Oct 4, 2004 1:45 PM by genman

    Connection.close() in messagequeue

    tonemeister

      Hi All
      Created a queue successfully on JBOSS 4.0.0

      Unless I close the connection however I get a horrendous thread leak resulting in Java running out of native threads.

      Closing the connection (conncetion.close()) results in stopping the thread leak, but then I get errors.

      Any Ideas as to what Im doing wrong??

      CODE SNIPPET:
      public void addToQueue(Document doc) throws AnException{
      InitialContext ctx = null;
      QueueConnection connection = null;
      QueueSession session = null;
      QueueSender sender = null;

      try {
      // Submit the request to the queue.
      ctx = new InitialContext();
      QueueConnectionFactory factory = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
      Queue queue = (Queue)ctx.lookup("queue/TheQueue");
      connection = factory.createQueueConnection();

      connection = factory.createQueueConnection();
      session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      sender = session.createSender(queue);

      sender = session.createSender(queue);
      TextMessage message = session.createTextMessage();
      message.setText(doc.getId());

      sender.send(message);
      }
      catch (NamingException ne) {
      throw new AnException("Failed to get initalcontext", ne);
      }
      catch (JMSException je) {
      throw new AnException("Failed to submit", je);
      }
      finally{
      try{
      connection.close();
      }
      catch(JMSException je){
      throw new AnException("Failed to close resource.", je);
      }

      ERROR:

      java.net.SocketException: Socket closed
      at java.net.SocketInputStream.read(SocketInputStream.java:162)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
      at org.jboss.util.stream.NotifyingBufferedInputStream.read(NotifyingBufferedInputStream.java:67)
      at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2200)
      at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2380)
      at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2447)
      at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2519)
      at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2668)
      at java.io.ObjectInputStream.readByte(ObjectInputStream.java:864)
      at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:279)
      at java.lang.Thread.run(Thread.java:595)
      2004-10-01 16:24:59,015 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run