| Author |
Message
|
| smalltalk2k |
Posted: Tue May 03, 2005 5:52 am Post subject: Is this way of listening for JMS messages inefficient? |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
The message class below is javax.jms.Message
The reciever is javax.jms.QueueReceiver.
Is this way of reading a Queue grossly inefficient for a system that would recieve roughly 40,000 straight mq messages in a 24 hour period. I'm asking in reference to the reciever.recieve(1) and the while loop. The system.out message of course would be removed.
The messages would be about 40 characters in length.
| Code: |
while (!isStopped()) {
Message m = receiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println(
Messages.getString("JMS_TEST.MESSAGE_RECIEVED_PREFIX") + message.getText()); //$NON-NLS-1$
if (message.getText().equalsIgnoreCase(Messages.getString("JMS_TEST.STOP")) //$NON-NLS-1$
|| message.getText().equalsIgnoreCase(Messages.getString("JMS_TEST.EXIT"))) { //$NON-NLS-1$
stopLoop();
}
} else {
System.out.println(
Messages.getString("JMS_TEST.MESSAGE_NON_TEXT_RECIEVED")); //$NON-NLS-1$
stopLoop();
}
}
} |
|
|
| Back to top |
|
 |
| fjb_saper |
Posted: Tue May 03, 2005 11:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20767 Location: LI,NY
|
I would like to see a MessageListener pattern applied here.
Remember as well to add a ConnectionErrorListener.
Enjoy  |
|
| Back to top |
|
 |
| dwitherspoon |
Posted: Tue May 24, 2005 12:18 pm Post subject: Caveat... |
|
|
 Acolyte
Joined: 09 Dec 2003 Posts: 59
|
A caveat to this is that if you want a graceful shutdown, you may have to resort to your first idea. That way you can be in a while (!stop) loop, and inside you do receive(x). Then every x millis you can be checking to see if you should gracefully stop.
This is what I do, but i have x set to 15 seconds...saying that I'm willing to wait 15 seconds (7 on average) for a graceful shutdown to happen. _________________ Good...Fast...Cheap. Choose any two. |
|
| Back to top |
|
 |
| fjb_saper |
Posted: Tue May 24, 2005 12:25 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20767 Location: LI,NY
|
You can also do a gracefull shutdown with a message listener.
a) stop the connection
b) set the MessageListener to null on the Consumer
c) set the ExceptionListener to null
d) release all JMS resources
Enjoy |
|
| Back to top |
|
 |
| dwitherspoon |
Posted: Tue May 24, 2005 12:31 pm Post subject: |
|
|
 Acolyte
Joined: 09 Dec 2003 Posts: 59
|
I actually had some trouble doing this because I was trying to shut things down from one thread while the listener thread was trying to process a message. I probably screwed it up because I was under the gun, so I punted and went back to the loop thing. _________________ Good...Fast...Cheap. Choose any two. |
|
| Back to top |
|
 |
|
|