Hello,
A logical take (without reference to spec or api):

The name:
setMessageListener indicates to me that we are overwriting the listener
i.e, why only the last one gets notified
              queueReceiver.setMessageListener(listener);

a method called addMessageListener would indicate to me the addition of
as opposed to overwriting of

    public void onMessage(Message message) {
        msg = (TextMessage) message;

        System.out.println(msg); // Print message to see all are
received

        synchronized (this) {
          this.notify();
        }
    }
    
    // add synchronization here onMessage notifys but no one is waiting

    public synchronized*** void run() {
       ...
       //synchronized (this) {
       //   this.wait();
       //}
       ...
    }

J

-----Original Message-----
From: Ron Cordell [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 10, 2001 12:31 PM
To: [EMAIL PROTECTED]
Subject: [developers] Message Listeners - odd behavior


I have modelled some simple message listeners to see how they work. I
took 
the simple AsynchQueueReceiver class in the SwiftMQ Sun samples
directory and 
ran three instances of it while using the SimpleQueueSender class to
send 
text messages. Everything worked as advertised in that the first
instance of 
AsynchQueueReceiver received message #1, the second instance received
Message 
#2, etc.

I then proceeded to modify the AsynchQueueReceiver and TextListener
classes 
so that the TextListener is a thread that waits until the onMessage() is

called. onMessage() issues a notify in order to wake up the thread and 
process the message.

    public void onMessage(Message message) {
        msg = (TextMessage) message;
        synchronized (this) {
          this.notify();
        }
    }
    
    public void run() {
      name = Thread.currentThread().getName();
      System.out.println(name + " starting up");
      while (!die && !Thread.currentThread().isInterrupted()) {
        try {
          synchronized(this) {
            this.wait();
          }
        } catch (InterruptedException ie) {
          die = true;
          continue;
        }
        try {
            System.out.println("Thread " + name + " Reading message: " +

msg.getText());
            Thread.currentThread().sleep(5000);
        } catch (JMSException e) {
            System.out.println("Exception in onMessage(): " +
e.toString());
        } catch (InterruptedException ie) {
        }
      }
    }


In AsynchQueueReceiver, I created 3 instances of the TextListener thread
and 
registered them as message listeners thus:

        try {
            queueSession = queueConnection.createQueueSession(false, 
                Session.AUTO_ACKNOWLEDGE);
            queueReceiver = queueSession.createReceiver(queue);
            for (int i=0; i<3; i++) {
              TextListener listener = new TextListener();
              Thread t = new Thread(tg, listener);
              t.start();
              queueReceiver.setMessageListener(listener);
            }
            queueConnection.start();
            System.out.println("To end program, enter Q or q, then
<return>");
            exitResult = SampleUtilities.wait_for_quit();

OK. When I use SimpleQueueSender, even though I have three threads
running, 
only the last thread gets the notification and does something with it. I
put 
in the Sleep(5000) to simulate some processing to see what happens if I
send 
another message while the first is still "processing". It turns out that

message is not processed.

Any ideas about why this is happening?

thanks,

-ronc

------------------------------------------------------
SwiftMQ developers mailing list * http://www.swiftmq.com
To unsubscribe from this list, send an eMail to 
[EMAIL PROTECTED] and write in the body of your message:
UNSUBSCRIBE developers <your-email-address>
Archive: http://www.mail-archive.com/developers@mail.iit.de/


------------------------------------------------------
SwiftMQ developers mailing list * http://www.swiftmq.com
To unsubscribe from this list, send an eMail to
[EMAIL PROTECTED] and write in the body of your message:
UNSUBSCRIBE developers <your-email-address>
Archive: http://www.mail-archive.com/developers@mail.iit.de/




Reply via email to