I had the same problem and "solved" it in the same way! Depending on the
frequency with which you browse the queue, the overhead may become too
big... am I wrong?
----- Original Message -----
From: "Michal Palicka" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 13, 2001 5:40 AM
Subject: [developers] Counting messages using QueueBrowser
> Hello,
>
> I'd like to count messages in a queue using the QueueBrowser.
> The queue should be examined at certain periods of time
> (let's say every 3 seconds). For my testing, I sent 22 messages
> to the queue. There was no receiver attached to the queue, so the
> number of messages was always supposed to be 22.
>
> I used the code below, but the output was incorrect:
>
> Mon Aug 13 10:07:38 CEST 2001: 22 messages in queue.
> Mon Aug 13 10:07:41 CEST 2001: 0 messages in queue.
> Mon Aug 13 10:07:44 CEST 2001: 0 messages in queue.
> Mon Aug 13 10:07:47 CEST 2001: 0 messages in queue.
> Mon Aug 13 10:07:50 CEST 2001: 0 messages in queue.
> ...
>
> ----------------
>
> try {
> queueConnection = queueConnectionFactory.createQueueConnection();
> queueSession = queueConnection.createQueueSession(false,
> Session.AUTO_ACKNOWLEDGE);
>
> queueBrowser = queueSession.createBrowser(queue);
>
> while (true) {
> long count = 0;
>
> /* queueBrowser = queueSession.createBrowser(queue); */
>
> Enumeration messageList = queueBrowser.getEnumeration();
> while (messageList.hasMoreElements()) {
> ++count;
> messageList.nextElement();
> }
> Date now = new Date(System.currentTimeMillis());
> System.out.println(now.toString() + ": "
> + String.valueOf(count) + " messages in queue.");
>
> /* queueBrowser.close(); */
>
> Thread.sleep(3000);
> }
> } catch (Exception e) {
> System.out.println("Exception occurred: " + e.toString());
> } finally {
> // release resources
> }
>
> ----------------
>
> Then I tried to use different approach. I changed the loop, so that
> I create a new QueueBrowser object, get the Enumeration of messages
> currently in the queue, count the messages, and close the QueueBrowser.
> The modified lines are enclosed in comments.
>
> The changed code works as expected:
>
> Mon Aug 13 10:34:12 CEST 2001: 22 messages in queue.
> Mon Aug 13 10:34:15 CEST 2001: 22 messages in queue.
> Mon Aug 13 10:34:18 CEST 2001: 22 messages in queue.
> Mon Aug 13 10:34:21 CEST 2001: 22 messages in queue.
> Mon Aug 13 10:34:24 CEST 2001: 22 messages in queue.
>
> ------------
>
> Does it mean that the QueueBrowser is kind of a "disposable" object?
> I would expect that it is be possible to re-use a single QueueBrowser
> to enumerate messages several times.
> Is this intended behaviour or a bug?
>
> Thank you in advance
> Michal Palicka, Cleverlance
>
>
> ------------------------------------------------------
> 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/