1 Reply Latest reply on Nov 7, 2006 6:06 PM by Elias Ross

    Synchronization Problem JMS Queue/Topic

    dpabhay Newbie

      I have scheduled(once every minute it empties the queue) receiver from the queue. And I have multiple browsers of the queue using the objects from the queue.


      I am using following code to browser through the objects on the queue.
      --------------
      Queue queue = getQueue();
      logger.info("Get queue. Name: " + queue.getQueueName());

      conn = getQueueConnection();
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

      brower = session.createBrowser(queue);
      Enumeration enumeration = brower.getEnumeration();

      while(enumeration.hasMoreElements())
      {
      Object message = enumeration.nextElement();
      if(message instanceof ObjectMessage)
      {
      ObjectMessage objMessage = (ObjectMessage)message;
      Object obj = objMessage.getObject();

      }
      }
      --------------

      And using the following code to receive/remove objects from the queue

      --------------
      conn = getQueueConnection();
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      receiver = session.createReceiver(queue);
      Message message = null;
      message = receiver.receive(TIME_TO_WAIT);
      while (message != null) {
      message = receiver.receive(TIME_TO_WAIT);
      }
      ----------------------------

      Task - the browsing of the queue and receiving from the queue must be mutually exclusive. Can I control that?

      Even greater problem is that I would like to have multiple browsing readers to be able to access the queue and still guarantee that the receivers will run within the reasonably comparable time with the schedule- time of the receiver (1 minute).

      How can I access the queue in such a way? Does JBoss have other control structures to do the kind of thing that I am trying to do? Any pointers and answers?

      Please assist.