1 2 Previous Next 15 Replies Latest reply on Mar 10, 2004 8:59 AM by f2racer Go to original post
      • 15. Re:
        f2racer

        adrian, is it possible that the container is asking for connections too fast? I put random sleeps in my client as well as in my server code which sends messages and the error goes away. Again, right now my code does nothing but pass messages around. Also both the client and server use the same MessageHelper class to send messages...

        public class MessageHelper {
        
         public void sendMessage(TextMessage msg, String queueName) {
         Context jndiContext = null;
         QueueConnection queueConnection = null;
         QueueConnectionFactory ref = null;
         Queue queue = null;
        
         try {
         jndiContext = new InitialContext();
         ref = (QueueConnectionFactory)jndiContext.lookup("ConnectionFactory");
         //ref = (QueueConnectionFactory)jndiContext.lookup("java:comp/env/jms/QueueFactory");
         //ref = (QueueConnectionFactory)jndiContext.lookup("jms/QueueFactory");
         queue = (Queue)jndiContext.lookup(queueName);
         } catch (NamingException e) {
         System.out.println("MessageHelper generated a NamingException: ");
         System.out.println(e.getMessage());
         e.printStackTrace();
         }
        
         try {
         queueConnection = ref.createQueueConnection();
         QueueSession queueSession = queueConnection.createQueueSession (false, Session.AUTO_ACKNOWLEDGE);
         QueueSender queueSender = queueSession.createSender(queue);
        
         queueSender.send(msg);
        
         //queueSender.close();
         //queueSession.close();
        
         queueConnection.close();
         queueConnection = null;
        
         // jndiContext.close();
        
         }
         catch (JMSException e) {
         System.out.println("MessageHelper generated a JMSException: ");
         System.out.println(e.getMessage());
         e.printStackTrace();
         } finally {
         try {
         if(queueConnection != null) {
         System.out.println("MessageHelper - Connection not closed, reclosing connection");
         queueConnection.close();
         queueConnection = null;
         }
        
         } catch (JMSException e) {
         System.out.println("MessageHelper generated a JMSException: ");
         System.out.println(e.getMessage());
         e.printStackTrace();
         }
         }
         }
        }
        


        1 2 Previous Next